update of decision trees

This commit is contained in:
mhjensen
2019-10-31 15:46:14 +01:00
parent 9fc81885cb
commit f10876b301
50 changed files with 395 additions and 184 deletions
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -177,7 +180,7 @@ MathJax.Hub.Config({
<a name="part0018"></a>
<!-- !split -->
<h2 id="___sec17" class="anchor">Simple Python Code to read in Data </h2>
<h2 id="___sec17" class="anchor">Simple Python Code to read in Data and perform Classification </h2>
<p>
@@ -186,6 +189,9 @@ MathJax.Hub.Config({
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> export_graphviz
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> StandardScaler, OneHotEncoder
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.compose</span> <span style="color: #008000; font-weight: bold">import</span> ColumnTransformer
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> Image
@@ -215,26 +221,37 @@ DATA_ID <span style="color: #666666">=</span> <span style="color: #BA2121">&quot
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">save_fig</span>(fig_id):
plt<span style="color: #666666">.</span>savefig(image_path(fig_id) <span style="color: #666666">+</span> <span style="color: #BA2121">&quot;.png&quot;</span>, format<span style="color: #666666">=</span><span style="color: #BA2121">&#39;png&#39;</span>)
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">&quot;ride.csv&quot;</span>),<span style="color: #BA2121">&#39;r&#39;</span>)
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">&quot;rideclass.csv&quot;</span>),<span style="color: #BA2121">&#39;r&#39;</span>)
<span style="color: #408080; font-style: italic"># Read the experimental data with Pandas</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>read_csv(infile,names <span style="color: #666666">=</span> (<span style="color: #BA2121">&#39;Outlook&#39;</span>,<span style="color: #BA2121">&#39;Temperature&#39;</span>,<span style="color: #BA2121">&#39;Humidity&#39;</span>,<span style="color: #BA2121">&#39;Wind&#39;</span>,<span style="color: #BA2121">&#39;Ride&#39;</span>))
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(ridedata)
display(ridedata)
<span style="color: #408080; font-style: italic"># Features and targets</span>
X <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">!=</span> <span style="color: #BA2121">&#39;Ride&#39;</span>]<span style="color: #666666">.</span>values
display(X)
y <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">==</span> <span style="color: #BA2121">&#39;Ride&#39;</span>]<span style="color: #666666">.</span>values
display(y)
<span style="color: #408080; font-style: italic"># Categorical variables to one-hot&#39;s</span>
onehotencoder <span style="color: #666666">=</span> OneHotEncoder(categories<span style="color: #666666">=</span><span style="color: #BA2121">&quot;auto&quot;</span>)
X <span style="color: #666666">=</span> ColumnTransformer([(<span style="color: #BA2121">&quot;&quot;</span>, onehotencoder)])<span style="color: #666666">.</span>fit_transform(X)
y<span style="color: #666666">.</span>shape
display(X)
display(y)
<span style="color: #408080; font-style: italic"># Create the encoder.</span>
encoder <span style="color: #666666">=</span> OneHotEncoder(handle_unknown<span style="color: #666666">=</span><span style="color: #BA2121">&quot;ignore&quot;</span>)
<span style="color: #408080; font-style: italic"># Assume for simplicity all features are categorical.</span>
encoder<span style="color: #666666">.</span>fit(X)
<span style="color: #408080; font-style: italic"># Apply the encoder.</span>
X <span style="color: #666666">=</span> encoder<span style="color: #666666">.</span>transform(X)
<span style="color: #008000; font-weight: bold">print</span>(X)
<span style="color: #408080; font-style: italic"># Then do a Classification tree</span>
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=2</span>)
tree_clf<span style="color: #666666">.</span>fit(X, y)
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">&quot;Train set accuracy with Decision Tree: {:.2f}&quot;</span><span style="color: #666666">.</span>format(tree_clf<span style="color: #666666">.</span>score(X,y)))
<span style="color: #408080; font-style: italic">#transfer to a decision tree graph</span>
export_graphviz(
tree_clf,
out_file<span style="color: #666666">=</span><span style="color: #BA2121">&quot;DataFiles/ride.dot&quot;</span>,
rounded<span style="color: #666666">=</span><span style="color: #008000">True</span>,
filled<span style="color: #666666">=</span><span style="color: #008000">True</span>
)
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png&#39;</span>
os<span style="color: #666666">.</span>system(cmd)
</pre></div>
<p>
<p>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -65,7 +65,10 @@ Automatically generated HTML file from DocOnce source
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -142,7 +145,7 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs015.html#___sec14" style="font-size: 80%;">Visualizing the Tree, Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs016.html#___sec15" style="font-size: 80%;">Visualizing the Tree, The Moons</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs017.html#___sec16" style="font-size: 80%;">Computing the Gini index</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs018.html#___sec17" style="font-size: 80%;">Simple Python Code to read in Data and perform Classification</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs019.html#___sec18" style="font-size: 80%;">Computing the Gini Factor</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs020.html#___sec19" style="font-size: 80%;">Entropy and the ID3 algorithm</a></li>
<!-- navigation toc: --> <li><a href="._DecisionTrees-bs021.html#___sec20" style="font-size: 80%;">Implementing the ID3 Algorithm</a></li>
@@ -732,7 +732,7 @@ The table here summarizes the various attributes and
<section>
<h2 id="___sec17">Simple Python Code to read in Data </h2>
<h2 id="___sec17">Simple Python Code to read in Data and perform Classification </h2>
<p>
@@ -741,6 +741,9 @@ The table here summarizes the various attributes and
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> DecisionTreeClassifier
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> train_test_split
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> export_graphviz
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.preprocessing</span> <span style="color: #8B008B; font-weight: bold">import</span> StandardScaler, OneHotEncoder
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.compose</span> <span style="color: #8B008B; font-weight: bold">import</span> ColumnTransformer
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> Image
@@ -770,26 +773,37 @@ DATA_ID = <span style="color: #CD5555">&quot;DataFiles/&quot;</span>
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">save_fig</span>(fig_id):
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">&quot;.png&quot;</span>, format=<span style="color: #CD5555">&#39;png&#39;</span>)
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">&quot;ride.csv&quot;</span>),<span style="color: #CD5555">&#39;r&#39;</span>)
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">&quot;rideclass.csv&quot;</span>),<span style="color: #CD5555">&#39;r&#39;</span>)
<span style="color: #228B22"># Read the experimental data with Pandas</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
ridedata = pd.read_csv(infile,names = (<span style="color: #CD5555">&#39;Outlook&#39;</span>,<span style="color: #CD5555">&#39;Temperature&#39;</span>,<span style="color: #CD5555">&#39;Humidity&#39;</span>,<span style="color: #CD5555">&#39;Wind&#39;</span>,<span style="color: #CD5555">&#39;Ride&#39;</span>))
ridedata = pd.DataFrame(ridedata)
display(ridedata)
<span style="color: #228B22"># Features and targets</span>
X = ridedata.loc[:, ridedata.columns != <span style="color: #CD5555">&#39;Ride&#39;</span>].values
display(X)
y = ridedata.loc[:, ridedata.columns == <span style="color: #CD5555">&#39;Ride&#39;</span>].values
display(y)
<span style="color: #228B22"># Categorical variables to one-hot&#39;s</span>
onehotencoder = OneHotEncoder(categories=<span style="color: #CD5555">&quot;auto&quot;</span>)
X = ColumnTransformer([(<span style="color: #CD5555">&quot;&quot;</span>, onehotencoder)]).fit_transform(X)
y.shape
display(X)
display(y)
<span style="color: #228B22"># Create the encoder.</span>
encoder = OneHotEncoder(handle_unknown=<span style="color: #CD5555">&quot;ignore&quot;</span>)
<span style="color: #228B22"># Assume for simplicity all features are categorical.</span>
encoder.fit(X)
<span style="color: #228B22"># Apply the encoder.</span>
X = encoder.transform(X)
<span style="color: #8B008B; font-weight: bold">print</span>(X)
<span style="color: #228B22"># Then do a Classification tree</span>
tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #B452CD">2</span>)
tree_clf.fit(X, y)
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">&quot;Train set accuracy with Decision Tree: {:.2f}&quot;</span>.format(tree_clf.score(X,y)))
<span style="color: #228B22">#transfer to a decision tree graph</span>
export_graphviz(
tree_clf,
out_file=<span style="color: #CD5555">&quot;DataFiles/ride.dot&quot;</span>,
rounded=<span style="color: #658b00">True</span>,
filled=<span style="color: #658b00">True</span>
)
cmd = <span style="color: #CD5555">&#39;dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png&#39;</span>
os.system(cmd)
</pre></div>
</section>
@@ -85,7 +85,10 @@ div { text-align: justify; text-justify: inter-word; }
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -705,7 +708,7 @@ The table here summarizes the various attributes and
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">Simple Python Code to read in Data </h2>
<h2 id="___sec17">Simple Python Code to read in Data and perform Classification </h2>
<p>
@@ -714,6 +717,9 @@ The table here summarizes the various attributes and
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> DecisionTreeClassifier
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.model_selection</span> <span style="color: #8B008B; font-weight: bold">import</span> train_test_split
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.tree</span> <span style="color: #8B008B; font-weight: bold">import</span> export_graphviz
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.preprocessing</span> <span style="color: #8B008B; font-weight: bold">import</span> StandardScaler, OneHotEncoder
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">sklearn.compose</span> <span style="color: #8B008B; font-weight: bold">import</span> ColumnTransformer
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> Image
@@ -743,26 +749,37 @@ DATA_ID = <span style="color: #CD5555">&quot;DataFiles/&quot;</span>
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">save_fig</span>(fig_id):
plt.savefig(image_path(fig_id) + <span style="color: #CD5555">&quot;.png&quot;</span>, format=<span style="color: #CD5555">&#39;png&#39;</span>)
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">&quot;ride.csv&quot;</span>),<span style="color: #CD5555">&#39;r&#39;</span>)
infile = <span style="color: #658b00">open</span>(data_path(<span style="color: #CD5555">&quot;rideclass.csv&quot;</span>),<span style="color: #CD5555">&#39;r&#39;</span>)
<span style="color: #228B22"># Read the experimental data with Pandas</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">IPython.display</span> <span style="color: #8B008B; font-weight: bold">import</span> display
ridedata = pd.read_csv(infile,names = (<span style="color: #CD5555">&#39;Outlook&#39;</span>,<span style="color: #CD5555">&#39;Temperature&#39;</span>,<span style="color: #CD5555">&#39;Humidity&#39;</span>,<span style="color: #CD5555">&#39;Wind&#39;</span>,<span style="color: #CD5555">&#39;Ride&#39;</span>))
ridedata = pd.DataFrame(ridedata)
display(ridedata)
<span style="color: #228B22"># Features and targets</span>
X = ridedata.loc[:, ridedata.columns != <span style="color: #CD5555">&#39;Ride&#39;</span>].values
display(X)
y = ridedata.loc[:, ridedata.columns == <span style="color: #CD5555">&#39;Ride&#39;</span>].values
display(y)
<span style="color: #228B22"># Categorical variables to one-hot&#39;s</span>
onehotencoder = OneHotEncoder(categories=<span style="color: #CD5555">&quot;auto&quot;</span>)
X = ColumnTransformer([(<span style="color: #CD5555">&quot;&quot;</span>, onehotencoder)]).fit_transform(X)
y.shape
display(X)
display(y)
<span style="color: #228B22"># Create the encoder.</span>
encoder = OneHotEncoder(handle_unknown=<span style="color: #CD5555">&quot;ignore&quot;</span>)
<span style="color: #228B22"># Assume for simplicity all features are categorical.</span>
encoder.fit(X)
<span style="color: #228B22"># Apply the encoder.</span>
X = encoder.transform(X)
<span style="color: #8B008B; font-weight: bold">print</span>(X)
<span style="color: #228B22"># Then do a Classification tree</span>
tree_clf = DecisionTreeClassifier(max_depth=<span style="color: #B452CD">2</span>)
tree_clf.fit(X, y)
<span style="color: #8B008B; font-weight: bold">print</span>(<span style="color: #CD5555">&quot;Train set accuracy with Decision Tree: {:.2f}&quot;</span>.format(tree_clf.score(X,y)))
<span style="color: #228B22">#transfer to a decision tree graph</span>
export_graphviz(
tree_clf,
out_file=<span style="color: #CD5555">&quot;DataFiles/ride.dot&quot;</span>,
rounded=<span style="color: #658b00">True</span>,
filled=<span style="color: #658b00">True</span>
)
cmd = <span style="color: #CD5555">&#39;dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png&#39;</span>
os.system(cmd)
</pre></div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
+30 -13
View File
@@ -90,7 +90,10 @@ div { text-align: justify; text-justify: inter-word; }
('Visualizing the Tree, Classification', 2, None, '___sec14'),
('Visualizing the Tree, The Moons', 2, None, '___sec15'),
('Computing the Gini index', 2, None, '___sec16'),
('Simple Python Code to read in Data', 2, None, '___sec17'),
('Simple Python Code to read in Data and perform Classification',
2,
None,
'___sec17'),
('Computing the Gini Factor', 2, None, '___sec18'),
('Entropy and the ID3 algorithm', 2, None, '___sec19'),
('Implementing the ID3 Algorithm', 2, None, '___sec20'),
@@ -710,7 +713,7 @@ The table here summarizes the various attributes and
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">Simple Python Code to read in Data </h2>
<h2 id="___sec17">Simple Python Code to read in Data and perform Classification </h2>
<p>
@@ -719,6 +722,9 @@ The table here summarizes the various attributes and
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> DecisionTreeClassifier
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.model_selection</span> <span style="color: #008000; font-weight: bold">import</span> train_test_split
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.tree</span> <span style="color: #008000; font-weight: bold">import</span> export_graphviz
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.preprocessing</span> <span style="color: #008000; font-weight: bold">import</span> StandardScaler, OneHotEncoder
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">sklearn.compose</span> <span style="color: #008000; font-weight: bold">import</span> ColumnTransformer
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> Image
@@ -748,26 +754,37 @@ DATA_ID <span style="color: #666666">=</span> <span style="color: #BA2121">&quot
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">save_fig</span>(fig_id):
plt<span style="color: #666666">.</span>savefig(image_path(fig_id) <span style="color: #666666">+</span> <span style="color: #BA2121">&quot;.png&quot;</span>, format<span style="color: #666666">=</span><span style="color: #BA2121">&#39;png&#39;</span>)
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">&quot;ride.csv&quot;</span>),<span style="color: #BA2121">&#39;r&#39;</span>)
infile <span style="color: #666666">=</span> <span style="color: #008000">open</span>(data_path(<span style="color: #BA2121">&quot;rideclass.csv&quot;</span>),<span style="color: #BA2121">&#39;r&#39;</span>)
<span style="color: #408080; font-style: italic"># Read the experimental data with Pandas</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">IPython.display</span> <span style="color: #008000; font-weight: bold">import</span> display
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>read_csv(infile,names <span style="color: #666666">=</span> (<span style="color: #BA2121">&#39;Outlook&#39;</span>,<span style="color: #BA2121">&#39;Temperature&#39;</span>,<span style="color: #BA2121">&#39;Humidity&#39;</span>,<span style="color: #BA2121">&#39;Wind&#39;</span>,<span style="color: #BA2121">&#39;Ride&#39;</span>))
ridedata <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(ridedata)
display(ridedata)
<span style="color: #408080; font-style: italic"># Features and targets</span>
X <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">!=</span> <span style="color: #BA2121">&#39;Ride&#39;</span>]<span style="color: #666666">.</span>values
display(X)
y <span style="color: #666666">=</span> ridedata<span style="color: #666666">.</span>loc[:, ridedata<span style="color: #666666">.</span>columns <span style="color: #666666">==</span> <span style="color: #BA2121">&#39;Ride&#39;</span>]<span style="color: #666666">.</span>values
display(y)
<span style="color: #408080; font-style: italic"># Categorical variables to one-hot&#39;s</span>
onehotencoder <span style="color: #666666">=</span> OneHotEncoder(categories<span style="color: #666666">=</span><span style="color: #BA2121">&quot;auto&quot;</span>)
X <span style="color: #666666">=</span> ColumnTransformer([(<span style="color: #BA2121">&quot;&quot;</span>, onehotencoder)])<span style="color: #666666">.</span>fit_transform(X)
y<span style="color: #666666">.</span>shape
display(X)
display(y)
<span style="color: #408080; font-style: italic"># Create the encoder.</span>
encoder <span style="color: #666666">=</span> OneHotEncoder(handle_unknown<span style="color: #666666">=</span><span style="color: #BA2121">&quot;ignore&quot;</span>)
<span style="color: #408080; font-style: italic"># Assume for simplicity all features are categorical.</span>
encoder<span style="color: #666666">.</span>fit(X)
<span style="color: #408080; font-style: italic"># Apply the encoder.</span>
X <span style="color: #666666">=</span> encoder<span style="color: #666666">.</span>transform(X)
<span style="color: #008000; font-weight: bold">print</span>(X)
<span style="color: #408080; font-style: italic"># Then do a Classification tree</span>
tree_clf <span style="color: #666666">=</span> DecisionTreeClassifier(max_depth<span style="color: #666666">=2</span>)
tree_clf<span style="color: #666666">.</span>fit(X, y)
<span style="color: #008000; font-weight: bold">print</span>(<span style="color: #BA2121">&quot;Train set accuracy with Decision Tree: {:.2f}&quot;</span><span style="color: #666666">.</span>format(tree_clf<span style="color: #666666">.</span>score(X,y)))
<span style="color: #408080; font-style: italic">#transfer to a decision tree graph</span>
export_graphviz(
tree_clf,
out_file<span style="color: #666666">=</span><span style="color: #BA2121">&quot;DataFiles/ride.dot&quot;</span>,
rounded<span style="color: #666666">=</span><span style="color: #008000">True</span>,
filled<span style="color: #666666">=</span><span style="color: #008000">True</span>
)
cmd <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png&#39;</span>
os<span style="color: #666666">.</span>system(cmd)
</pre></div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -6,11 +6,11 @@ edge [fontname=helvetica] ;
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"] ;
3 [label="area error <= 48.975\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"] ;
5 [label="mean area <= 469.25\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 ;
@@ -22,7 +22,7 @@ edge [fontname=helvetica] ;
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"] ;
11 [label="worst texture <= 24.785\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 ;
@@ -30,11 +30,11 @@ edge [fontname=helvetica] ;
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"] ;
15 [label="worst perimeter <= 116.8\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"] ;
17 [label="worst texture <= 18.445\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 ;
@@ -48,10 +48,10 @@ edge [fontname=helvetica] ;
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"] ;
24 [label="fractal dimension error <= 0.013\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"] ;
25 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139ff"] ;
24 -> 25 ;
26 [label="gini = 0.0\nsamples = 135\nvalue = [[0, 135]\n[135, 0]]", fillcolor="#e58139ff"] ;
26 [label="gini = 0.0\nsamples = 1\nvalue = [[1, 0]\n[0, 1]]", fillcolor="#e58139ff"] ;
24 -> 26 ;
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 KiB

After

Width:  |  Height:  |  Size: 217 KiB

+26 -12
View File
@@ -629,7 +629,7 @@
"</tbody>\n",
"</table>\n",
"\n",
"## Simple Python Code to read in Data"
"## Simple Python Code to read in Data and perform Classification"
]
},
{
@@ -644,6 +644,9 @@
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"from sklearn.tree import DecisionTreeClassifier\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.tree import export_graphviz\n",
"from sklearn.preprocessing import StandardScaler, OneHotEncoder\n",
"from sklearn.compose import ColumnTransformer\n",
"from IPython.display import Image \n",
@@ -673,26 +676,37 @@
"def save_fig(fig_id):\n",
" plt.savefig(image_path(fig_id) + \".png\", format='png')\n",
"\n",
"infile = open(data_path(\"ride.csv\"),'r')\n",
"infile = open(data_path(\"rideclass.csv\"),'r')\n",
"\n",
"# Read the experimental data with Pandas\n",
"from IPython.display import display\n",
"ridedata = pd.read_csv(infile,names = ('Outlook','Temperature','Humidity','Wind','Ride'))\n",
"ridedata = pd.DataFrame(ridedata)\n",
"display(ridedata)\n",
"\n",
"# Features and targets\n",
"X = ridedata.loc[:, ridedata.columns != 'Ride'].values\n",
"display(X)\n",
"y = ridedata.loc[:, ridedata.columns == 'Ride'].values\n",
"display(y)\n",
"# Categorical variables to one-hot's\n",
"onehotencoder = OneHotEncoder(categories=\"auto\")\n",
"\n",
"X = ColumnTransformer([(\"\", onehotencoder)]).fit_transform(X)\n",
"y.shape\n",
"\n",
"display(X)\n",
"display(y)"
"# Create the encoder.\n",
"encoder = OneHotEncoder(handle_unknown=\"ignore\")\n",
"# Assume for simplicity all features are categorical.\n",
"encoder.fit(X) \n",
"# Apply the encoder.\n",
"X = encoder.transform(X)\n",
"print(X)\n",
"# Then do a Classification tree\n",
"tree_clf = DecisionTreeClassifier(max_depth=2)\n",
"tree_clf.fit(X, y)\n",
"print(\"Train set accuracy with Decision Tree: {:.2f}\".format(tree_clf.score(X,y)))\n",
"#transfer to a decision tree graph\n",
"export_graphviz(\n",
" tree_clf,\n",
" out_file=\"DataFiles/ride.dot\",\n",
" rounded=True,\n",
" filled=True\n",
")\n",
"cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'\n",
"os.system(cmd)"
]
},
{
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
digraph Tree {
node [shape=box, style="filled, rounded", color="black", fontname=helvetica] ;
edge [fontname=helvetica] ;
0 [label="X[7] <= 0.5\ngini = 0.48\nsamples = 15\nvalue = [4, 10, 1]", fillcolor="#39e5818b"] ;
1 [label="X[1] <= 0.5\ngini = 0.408\nsamples = 14\nvalue = [4, 10, 0]", fillcolor="#39e58199"] ;
0 -> 1 [labeldistance=2.5, labelangle=45, headlabel="True"] ;
2 [label="gini = 0.48\nsamples = 10\nvalue = [4, 6, 0]", fillcolor="#39e58155"] ;
1 -> 2 ;
3 [label="gini = 0.0\nsamples = 4\nvalue = [0, 4, 0]", fillcolor="#39e581ff"] ;
1 -> 3 ;
4 [label="gini = 0.0\nsamples = 1\nvalue = [0, 0, 1]", fillcolor="#8139e5ff"] ;
0 -> 4 [labeldistance=2.5, labelangle=-45, headlabel="False"] ;
}
+26 -11
View File
@@ -498,13 +498,16 @@ The table here summarizes the various attributes and
!split
===== Simple Python Code to read in Data =====
===== Simple Python Code to read in Data and perform Classification =====
!bc pycod
# Common imports
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
from sklearn.tree import export_graphviz
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer
from IPython.display import Image
@@ -534,26 +537,38 @@ def data_path(dat_id):
def save_fig(fig_id):
plt.savefig(image_path(fig_id) + ".png", format='png')
infile = open(data_path("ride.csv"),'r')
infile = open(data_path("rideclass.csv"),'r')
# Read the experimental data with Pandas
from IPython.display import display
ridedata = pd.read_csv(infile,names = ('Outlook','Temperature','Humidity','Wind','Ride'))
ridedata = pd.DataFrame(ridedata)
display(ridedata)
# Features and targets
X = ridedata.loc[:, ridedata.columns != 'Ride'].values
display(X)
y = ridedata.loc[:, ridedata.columns == 'Ride'].values
display(y)
# Categorical variables to one-hot's
onehotencoder = OneHotEncoder(categories="auto")
X = ColumnTransformer([("", onehotencoder)]).fit_transform(X)
y.shape
# Create the encoder.
encoder = OneHotEncoder(handle_unknown="ignore")
# Assume for simplicity all features are categorical.
encoder.fit(X)
# Apply the encoder.
X = encoder.transform(X)
print(X)
# Then do a Classification tree
tree_clf = DecisionTreeClassifier(max_depth=2)
tree_clf.fit(X, y)
print("Train set accuracy with Decision Tree: {:.2f}".format(tree_clf.score(X,y)))
#transfer to a decision tree graph
export_graphviz(
tree_clf,
out_file="DataFiles/ride.dot",
rounded=True,
filled=True
)
cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'
os.system(cmd)
display(X)
display(y)
!ec
@@ -34,45 +34,35 @@ def data_path(dat_id):
def save_fig(fig_id):
plt.savefig(image_path(fig_id) + ".png", format='png')
infile = open(data_path("ride.csv"),'r')
infile = open(data_path("rideclass.csv"),'r')
# Read the experimental data with Pandas
from IPython.display import display
ridedata = pd.read_csv(infile,names = ('Outlook','Temperature','Humidity','Wind','Ride'))
ridedata = pd.DataFrame(ridedata)
display(ridedata)
# Features and targets
X = ridedata.loc[:, ridedata.columns != 'Ride'].values
display(X)
y = ridedata.loc[:, ridedata.columns == 'Ride'].values
display(y)
# Categorical variables to one-hot's
onehotencoder = OneHotEncoder(categories="auto")
X = ColumnTransformer([("", onehotencoder)]).fit_transform(X)
y.shape
display(X)
display(y)
"""
X = pd.DataFrame(ridedata.data, columns=ridedata.feature_names)
y = pd.Categorical.from_codes(ridedata.target, ridedata.target_names)
y = pd.get_dummies(y)
# Create the encoder.
encoder = OneHotEncoder(handle_unknown="ignore")
# Assume for simplicity all features are categorical.
encoder.fit(X)
# Apply the encoder.
X = encoder.transform(X)
print(X)
# Then do a Classification tree
tree_clf = DecisionTreeClassifier(max_depth=2)
tree_clf.fit(X, y)
print("Train set accuracy with Decision Tree: {:.2f}".format(tree_clf.score(X,y)))
#transfer to a decision tree graph
export_graphviz(
tree_clf,
out_file="ride.dot",
feature_names=tree_clf.feature_names,
class_names=tree_clf.target_names,
out_file="DataFiles/ride.dot",
rounded=True,
filled=True
)
"""
cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'
os.system(cmd)