diff --git a/doc/pub/week44/html/._week44-bs000.html b/doc/pub/week44/html/._week44-bs000.html
index 2075e6cdc..6872062e3 100644
--- a/doc/pub/week44/html/._week44-bs000.html
+++ b/doc/pub/week44/html/._week44-bs000.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
- Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+ Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -331,7 +399,7 @@ MathJax.Hub.Config({
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -347,7 +415,7 @@ MathJax.Hub.Config({
-Aug 23, 2022
+Oct 30, 2022
@@ -372,7 +440,7 @@ MathJax.Hub.Config({
9
10
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs001.html b/doc/pub/week44/html/._week44-bs001.html
index 0a41ac773..099b77cb5 100644
--- a/doc/pub/week44/html/._week44-bs001.html
+++ b/doc/pub/week44/html/._week44-bs001.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -332,16 +400,14 @@ MathJax.Hub.Config({
Overview of week 44
- Thursday: Wrapping up PCA from last week, Clustering and basics of decision trees, classification and regression algorithms
- Friday: Decision trees, voting models and bagging
+ Thursday: Basics of decision trees, classification and regression algorithms
+ Friday: Decision trees and ensemble models (bagging and random forests)
@@ -352,7 +418,6 @@ MathJax.Hub.Config({
Decision Trees: Geron's chapter 6 covers decision trees while ensemble models, voting and bagging are discussed in chapter 7. See also lecture from STK-IN4300, lecture 7 . Chapter 9.2 of Hastie et al contains also a good discussion.
- Clustering and PCA, see Geron's chapter 8 and Lecture notes . Bishop's chapter 9.1 is also a good read.
@@ -374,7 +439,7 @@ MathJax.Hub.Config({
10
11
...
- 65
+ 81
»
diff --git a/doc/pub/week44/html/._week44-bs002.html b/doc/pub/week44/html/._week44-bs002.html
index c36cb8c1a..c26f3978b 100644
--- a/doc/pub/week44/html/._week44-bs002.html
+++ b/doc/pub/week44/html/._week44-bs002.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
- Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+ Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -357,7 +425,7 @@ accelerate scientific discovery.
11
12
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs003.html b/doc/pub/week44/html/._week44-bs003.html
index 18e11137b..54fa6c145 100644
--- a/doc/pub/week44/html/._week44-bs003.html
+++ b/doc/pub/week44/html/._week44-bs003.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -479,7 +547,7 @@ plt
. show()
12
13
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs004.html b/doc/pub/week44/html/._week44-bs004.html
index 42a2e2850..845bbdc9c 100644
--- a/doc/pub/week44/html/._week44-bs004.html
+++ b/doc/pub/week44/html/._week44-bs004.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,23 +397,31 @@ MathJax.Hub.Config({
-
Learning Rate and more
+
Decision trees, overarching aims
-
When developing your own gradient descent code, it is useful to test
-it first on a standard ordinary least squares problem. Then the
-Hessian matrix is determined by the design matrix only, namely
-\( \boldsymbol{H}\propto \boldsymbol{X}^T\boldsymbol{X} \).
+
We start here with the most basic algorithm, the so-called decision
+tree. With this basic algorithm we can in turn build more complex
+networks, spanning from homogeneous and heterogenous forests (bagging,
+random forests and more) to one of the most popular supervised
+algorithms nowadays, the extreme gradient boosting, or just
+XGBoost. But let us start with the simplest possible ingredient.
-
The optimal learning rate is determined by the inverse of the largest
-eigenvalue of \( \boldsymbol{H} \). This can be used as a guideline for the
-learning rate guess.
+
Decision trees are supervised learning algorithms used for both,
+classification and regression tasks.
-
Keeping this fixed, can aid in studyng the dependence on say the mean
-square value for OLS as function of the number of batches and epochs
-in your stochastic gradient descent code. See for example the code
-examples for week 40 (right before the neural network material).
+
The main idea of decision trees
+is to find those descriptive features which contain the most
+information regarding the target feature and then split the dataset
+along the values of these features such that the target feature values
+for the resulting underlying datasets are as pure as possible.
+
+
+
The descriptive features which reproduce best the target/output features are normally said
+to be the most informative ones. The process of finding the most
+informative feature is done until we accomplish a stopping criteria
+where we then finally end up in so called leaf nodes .
@@ -367,7 +443,7 @@ examples for week 40 (right before the neural network material).
13
14
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs005.html b/doc/pub/week44/html/._week44-bs005.html
index 54808bcc7..575907e94 100644
--- a/doc/pub/week44/html/._week44-bs005.html
+++ b/doc/pub/week44/html/._week44-bs005.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,10 +397,18 @@ MathJax.Hub.Config({
-
Thursday, Principal Component Analysis
+
Basics of a tree
-
For the principal component analysis,
-see slides from week 43 , in particular from slide 28 and forward
+
A decision tree is typically divided into a root node , the interior nodes ,
+and the final leaf nodes or just leaves . These entities are then connected by so-called branches .
+
+
+
The leaf nodes
+contain the predictions we will make for new query instances presented
+to our trained model. This is possible since the model has
+learned the underlying structure of the training data and hence can,
+given some assumptions, make predictions about the target feature value
+(class) of unseen query instances.
@@ -355,7 +431,7 @@ see slides from 14
15
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs006.html b/doc/pub/week44/html/._week44-bs006.html
index cc41d73c5..3ea013914 100644
--- a/doc/pub/week44/html/._week44-bs006.html
+++ b/doc/pub/week44/html/._week44-bs006.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,35 +397,9 @@ MathJax.Hub.Config({
-
A kind of Bird's view on PCA
+
A Sketch of a Tree, Regression problem
-
Why do we maximize variance during Principal Component Analysis?
-
-
Variance is a measure of the variability of the data you
-have. Potentially the number of components is infinite, so you want to "squeeze" the most
-information in each component of the finite set you build.
-
-
-
If, to exaggerate, you were to select a single principal component,
-you would want it to account for the most variability possible: hence
-the search for maximum variance, so that the one component collects
-the most "uniqueness" from the data set.
-
-
-
Maximizing the component vector variances is the same as maximizing
-the 'uniqueness' of those vectors. The vectors are as distant
-from each other as possible (orthogonal to each other).
-
-
-
Take for example a situation where you have 2 lines that are
-orthogonal in a 3D space. You can capture the environment much more
-completely with those orthogonal lines than 2 lines that are parallel
-(or nearly parallel). When applied to very high dimensional states
-using very few vectors, this becomes a much more important
-relationship among the vectors to maintain. In a linear algebra sense
-you want independent rows to be produced by PCA, otherwise some of
-those rows will be redundant.
-
+
@@ -380,7 +422,7 @@ those rows will be redundant.
15
16
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs007.html b/doc/pub/week44/html/._week44-bs007.html
index d98ea8adf..e015d7050 100644
--- a/doc/pub/week44/html/._week44-bs007.html
+++ b/doc/pub/week44/html/._week44-bs007.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,19 +397,9 @@ MathJax.Hub.Config({
-
Thursday: Clustering and Unsupervised Learning
+
A Sketch of a Tree, Classification problem
-
In general terms cluster analysis, or clustering, is the task of grouping a
-data-set into different distinct categories based on some measure of equality of
-the data. This measure is often referred to as a metric or similarity
-measure in the literature (note: sometimes we deal with a dissimilarity
-measure instead). Usually, these metrics are formulated as some kind of
-distance function between points in a high-dimensional space.
-
-
-
The simplest, and also the most
-common is the Euclidean distance .
-
+
@@ -365,7 +423,7 @@ common is the Euclidean distance .
16
17
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs008.html b/doc/pub/week44/html/._week44-bs008.html
index 2ec497186..86198e48b 100644
--- a/doc/pub/week44/html/._week44-bs008.html
+++ b/doc/pub/week44/html/._week44-bs008.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,14 +397,15 @@ MathJax.Hub.Config({
-
Basic Idea of the \( k \)-means Clustering Algorithm
+
A typical Decision Tree with its pertinent Jargon, Classification Problem
-
The simplest of all clustering algorithms is the k-means algorithm
-, sometimes also referred to as Lloyds algorithm . It is the simplest and also
-the most common. From its simplicity it obtains both strengths and weaknesses.
-These will be discussed in more detail later. The \( k \)-means algorithm is a
-centroid based clustering algorithm.
-
+
+
+
+
+
+
+
This tree was produced using the Wisconsin cancer data (discussed here as well, see code examples below) using Scikit-Learn 's decision tree classifier. Here we have used the so-called gini index (see below) to split the various branches.
@@ -361,7 +430,7 @@ These will be discussed in more detail later. The \( k \)-means algorithm is a
17
18
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs009.html b/doc/pub/week44/html/._week44-bs009.html
index 2cdac8800..fec5c6573 100644
--- a/doc/pub/week44/html/._week44-bs009.html
+++ b/doc/pub/week44/html/._week44-bs009.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,28 +397,20 @@ MathJax.Hub.Config({
-
The \( k \)-means Algorithm
+
General Features
-
Assume, we are given \( n \) data points and we wish to split the data into \( K < n \)
-different categories, or clusters. We label each cluster by an integer
+
The overarching approach to decision trees is a top-down approach.
+
+
+ A leaf provides the classification of a given instance.
+ A node specifies a test of some attribute of the instance.
+ A branch corresponds to a possible values of an attribute.
+ An instance is classified by starting at the root node of the tree, testing the attribute specified by this node, then moving down the tree branch corresponding to the value of the attribute in the given example.
+
+
This process is then repeated for the subtree rooted at the new
+node.
-$$ k\in\{1, \cdots, K \}.
-$$
-
-
In the basic k-means algorithm each point is assigned to only
-one cluster \( k \), and these assignments are non-injective i.e. many-to-one. We
-can think of these mappings as an encoder \( k = C(i) \), which assigns the \( i \)-th
-data-point \( \bf x_i \) to the \( k \)-th cluster.
-
-
-
\( k \)-means algorithm in words:
-
- We start with guesses / random initializations of our \( k \) cluster centers/centroids
- For each centroid the points that are most similar are identified
- Then we move / replace each centroid with a coordinate average of all the points that were assigned to that centroid.
- Iterate 2-3 until the centroids no longer move (to some tolerance)
-
diff --git a/doc/pub/week44/html/._week44-bs010.html b/doc/pub/week44/html/._week44-bs010.html
index 5da221083..2bde2f61d 100644
--- a/doc/pub/week44/html/._week44-bs010.html
+++ b/doc/pub/week44/html/._week44-bs010.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,25 +397,19 @@ MathJax.Hub.Config({
-
Basic Math of the \( k \)-means Algorithm
+
How do we set it up?
-
We assume we have \( n \) data-points
-$$
-\begin{equation}\tag{1}
- \boldsymbol{x_i} = \{x_{i, 1}, \cdots, x_{i, p}\}\in\mathbb{R}^p.
-\end{equation}
-$$
-
-
which we wish to group into \( K < n \) clusters. For our dissimilarity measure we
-use the squared Euclidean distance
+
In simplified terms, the process of training a decision tree and
+predicting the target features of query instances is as follows:
-$$
-\begin{equation}\tag{2}
- d(\boldsymbol{x_i}, \boldsymbol{x_i'}) = \sum_{j=1}^p(x_{ij} - x_{i'j})^2
- = ||\boldsymbol{x_i} - \boldsymbol{x_{i'}}||^2
-\end{equation}
-$$
+
+ Present a dataset containing of a number of training instances characterized by a number of descriptive features and a target feature
+ Train the decision tree model by continuously splitting the target feature along the values of the descriptive features using a measure of information gain during the training process
+ Grow the tree until we accomplish a stopping criteria create leaf nodes which represent the predictions we want to make for new query instances
+ Show query instances to the tree and run down the tree until we arrive at leaf nodes
+
+
Then we are essentially done!
@@ -374,7 +436,7 @@ $$
19
20
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs011.html b/doc/pub/week44/html/._week44-bs011.html
index 690db9247..c983300d3 100644
--- a/doc/pub/week44/html/._week44-bs011.html
+++ b/doc/pub/week44/html/._week44-bs011.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,29 +397,117 @@ MathJax.Hub.Config({
-
Within Cluster Point Scatter
+
Decision trees and Regression
-
We define the so called within-cluster point scatter which gives us a
-measure of how close each data point assigned to the same cluster tends to be to
-the all the others.
-
-$$
-\begin{equation}\tag{3}
- W(C) = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k}
- \sum_{C(i')=k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) =
- \sum_{k=1}^KN_k\sum_{C(i)=k}||\boldsymbol{x_i} - \boldsymbol{\overline{x_k}}||^2
-\end{equation}
-$$
+
+
-
where \( \boldsymbol{\overline{x_k}} \) is the mean vector associated with the \( k \)-th
-cluster, and \( N_k = \sum_{i=1}^nI(C(i) = k) \), where the \( I() \) notation is
-similar to the Kronecker delta (Commonly used in statistics, it just means that
-when \( i = k \) we have the encoder \( C(i) \) ). In other words, the within-cluster
-scatter measures the compactness of each cluster with respect to the data points
-assigned to each cluster. This is the quantity that the \( k \)-means algorithm aims
-to minimize. We refer to this quantity \( W(C) \) as the within cluster scatter
-because of its relation to the total scatter .
-
@@ -378,7 +534,7 @@ because of its relation to the total scatter .
20
21
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs012.html b/doc/pub/week44/html/._week44-bs012.html
index d49c18150..8ad73d913 100644
--- a/doc/pub/week44/html/._week44-bs012.html
+++ b/doc/pub/week44/html/._week44-bs012.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,24 +397,27 @@ MathJax.Hub.Config({
-
More Details
+
Building a tree, regression
+
+
There are mainly two steps
+
+ We split the predictor space (the set of possible values \( x_1,x_2,\dots, x_p \)) into \( J \) distinct and non-non-overlapping regions, \( R_1,R_2,\dots,R_J \).
+ For every observation that falls into the region \( R_j \) , we make the same prediction, which is simply the mean of the response values for the training observations in \( R_j \).
+
+
How do we construct the regions \( R_1,\dots,R_J \)? In theory, the
+regions could have any shape. However, we choose to divide the
+predictor space into high-dimensional rectangles, or boxes, for
+simplicity and for ease of interpretation of the resulting predictive
+model. The goal is to find boxes \( R_1,\dots,R_J \) that minimize the
+MSE, given by
+
-
We have
$$
-\begin{equation}\tag{4}
- T = W(C) + B(C) = \frac{1}{2}\sum_{i=1}^n
- \sum_{i'=1}^nd(\boldsymbol{x_i}, \boldsymbol{x_{i'}})
- = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k}
- \Big(\sum_{C(i') = k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})
- + \sum_{C(i')\neq k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})\Big).
-\end{equation}
+\sum_{j=1}^J\sum_{i\in R_j}(y_i-\overline{y}_{R_j})^2,
$$
-
This is a quantity that is conserved throughout the \( k \)-means algorithm. It can
-be thought of as the total amount of information in the data, and it is composed
-of the aforementioned within-cluster scatter and the between-cluster scatter
-\( B(C) \). In methods such as principle component analysis the total scatter is not
-conserved.
+
where \( \overline{y}_{R_j} \) is the mean response for the training observations
+within box \( j \).
@@ -374,7 +445,7 @@ conserved.
21
22
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs013.html b/doc/pub/week44/html/._week44-bs013.html
index ffcb87b8c..4363ca9cc 100644
--- a/doc/pub/week44/html/._week44-bs013.html
+++ b/doc/pub/week44/html/._week44-bs013.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,15 +397,21 @@ MathJax.Hub.Config({
-
Total Cluster Variance
-
Given a cluster mean \( \boldsymbol{m_k} \) we define the total cluster variance
-$$
-\begin{equation}\tag{5}
- \min_{C, \{\boldsymbol{m_k}\}_1^K}\sum_{k=1}^KN_k\sum||\boldsymbol{x_i} - \boldsymbol{m_k}||^2
-\end{equation}
-$$
+
A top-down approach, recursive binary splitting
-
Now we have all the pieces necessary to formally revisit the \( k \)-means algorithm.
+
Unfortunately, it is computationally infeasible to consider every
+possible partition of the feature space into \( J \) boxes. The common
+strategy is to take a top-down approach
+
+
+
The approach is top-down because it begins at the top of the tree (all
+observations belong to a single region) and then successively splits
+the predictor space; each split is indicated via two new branches
+further down on the tree. It is greedy because at each step of the
+tree-building process, the best split is made at that particular step,
+rather than looking ahead and picking a split that will lead to a
+better tree in some future step.
+
@@ -364,7 +438,7 @@ $$
22
23
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs014.html b/doc/pub/week44/html/._week44-bs014.html
index f6802ec5c..55c1b7cb0 100644
--- a/doc/pub/week44/html/._week44-bs014.html
+++ b/doc/pub/week44/html/._week44-bs014.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,15 +397,54 @@ MathJax.Hub.Config({
-
The \( k \)-means Clustering Algorithm
+
Making a tree
-
The \( k \)-means clustering algorithm goes as follows
+
In order to implement the recursive binary splitting we start by selecting
+the predictor \( x_j \) and a cutpoint \( s \) that splits the predictor space into two regions \( R_1 \) and \( R_2 \)
+
+$$
+\left\{X\vert x_j < s\right\},
+$$
+
+
and
+$$
+\left\{X\vert x_j \geq s\right\},
+$$
+
+
so that we obtain the lowest MSE, that is
+$$
+\sum_{i:x_i\in R_j}(y_i-\overline{y}_{R_1})^2+\sum_{i:x_i\in R_2}(y_i-\overline{y}_{R_2})^2,
+$$
+
+
which we want to minimize by considering all predictors
+\( x_1,x_2,\dots,x_p \). We consider also all possible values of \( s \) for
+each predictor. These values could be determined by randomly assigned
+numbers or by starting at the midpoint and then proceed till we find
+an optimal value.
+
+
+
For any \( j \) and \( s \), we define the pair of half-planes where
+\( \overline{y}_{R_1} \) is the mean response for the training
+observations in \( R_1(j,s) \), and \( \overline{y}_{R_2} \) is the mean
+response for the training observations in \( R_2(j,s) \).
+
+
+
Finding the values of \( j \) and \( s \) that minimize the above equation can be
+done quite quickly, especially when the number of features \( p \) is not
+too large.
+
+
+
Next, we repeat the process, looking
+for the best predictor and best cutpoint in order to split the data
+further so as to minimize the MSE within each of the resulting
+regions. However, this time, instead of splitting the entire predictor
+space, we split one of the two previously identified regions. We now
+have three regions. Again, we look to split one of these three regions
+further, so as to minimize the MSE. The process continues until a
+stopping criterion is reached; for instance, we may continue until no
+region contains more than five observations.
+
-
- For a given cluster assignment \( C \), and \( k \) cluster means \( \left\{m_1, \cdots, m_k\right\} \). We minimize the total cluster variance with respect to the cluster means \( \{m_k\} \) yielding the means of the currently assigned clusters.
- Given a current set of \( k \) means \( \{m_k\} \) the total cluster variance is minimized by assigning each observation to the closest (current) cluster mean. That is $$C(i) = \underset{1\leq k\leq K}{\mathrm{argmin}} ||\boldsymbol{x_i} - \boldsymbol{m_k}||^2$$
- Steps 1 and 2 are repeated until the assignments do not change.
-
diff --git a/doc/pub/week44/html/._week44-bs015.html b/doc/pub/week44/html/._week44-bs015.html
index 5723078ac..21bf54e15 100644
--- a/doc/pub/week44/html/._week44-bs015.html
+++ b/doc/pub/week44/html/._week44-bs015.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -328,16 +396,25 @@ MathJax.Hub.Config({
-
-
Summarizing
+
+
Pruning the tree
+
+
The above procedure is rather straightforward, but leads often to
+overfitting and unnecessarily large and complicated trees. The basic
+idea is to grow a large tree \( T_0 \) and then prune it back in order to
+obtain a subtree. A smaller tree with fewer splits (fewer regions) can
+lead to smaller variance and better interpretation at the cost of a
+little more bias.
+
+
+
The so-called Cost complexity pruning algorithm gives us a
+way to do just this. Rather than considering every possible subtree,
+we consider a sequence of trees indexed by a nonnegative tuning
+parameter \( \alpha \).
+
+
+
Read more at the following Scikit-Learn link on pruning .
-
- Before we start we specify a number \( k \) which is the number of clusters we want to try to separate our data into.
- We initially choose \( k \) random data points in our data as our initial centroids, or means (this is where the name comes from).
- Assign each data point to their closest centroid, based on the squared Euclidean distance.
- For each of the \( k \) cluster we update the centroid by calculating new mean values for all the data points in the cluster.
- Iteratively minimize the within cluster scatter by performing steps (3, 4) until the new assignments stop changing (can be to some tolerance) or until a maximum number of iterations have passed.
-
diff --git a/doc/pub/week44/html/._week44-bs016.html b/doc/pub/week44/html/._week44-bs016.html
index 826e925e0..7445e0486 100644
--- a/doc/pub/week44/html/._week44-bs016.html
+++ b/doc/pub/week44/html/._week44-bs016.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,125 +397,36 @@ MathJax.Hub.Config({
-
Writing our own Code, the Data Set
+
Cost complexity pruning
-
Let us now program the most basic version of the algorithm using nothing but
-Python with numpy arrays. This code is kept intentionally simple to gradually
-progress our understanding. There is no vectorization of any kind, and even most
-helper functions are not utilized.
+
For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that
+$$
+\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T},
+$$
+
+
is as small as possible. Here \( \overline{T} \) is
+the number of terminal nodes of the tree \( T \) , \( R_m \) is the
+rectangle (i.e. the subset of predictor space) corresponding to the \( m \)-th terminal node.
-
We need first a dataset to do our cluster analysis on. In our case
-this is a plain vanilla data set using random numbers using a
-Gaussian distribution.
+
The tuning parameter \( \alpha \) controls a trade-off between the subtree’s
+complexity and its fit to the training data. When \( \alpha = 0 \), then the
+subtree \( T \) will simply equal \( T_0 \),
+because then the above equation just measures the
+training error.
+However, as \( \alpha \) increases, there is a price to pay for
+having a tree with many terminal nodes. The above equation will
+tend to be minimized for a smaller subtree.
-
-
-
-
-
Next we define functions, for ease of use later, to generate Gaussians and to
-set up our toy data set.
+
It turns out that as we increase \( \alpha \) from zero
+branches get pruned from the tree in a nested and predictable fashion,
+so obtaining the whole sequence of subtrees as a function of \( \alpha \) is
+easy. We can select a value of \( \alpha \) using a validation set or using
+cross-validation. We then return to the full data set and obtain the
+subtree corresponding to \( \alpha \).
-
-
-
-
diff --git a/doc/pub/week44/html/._week44-bs017.html b/doc/pub/week44/html/._week44-bs017.html
index dfb468b0b..2cedd4d78 100644
--- a/doc/pub/week44/html/._week44-bs017.html
+++ b/doc/pub/week44/html/._week44-bs017.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,65 +397,24 @@ MathJax.Hub.Config({
-
Implementing the \( k \)-means Algorithm
+
Schematic Regression Procedure
-
With the above dataset we start
-implementing the \( k \)-means algorithm.
-
+
+
+
-
-
-
@@ -416,7 +443,7 @@ cluster_labels
= np
26
27
...
- 65
+ 81
»
diff --git a/doc/pub/week44/html/._week44-bs018.html b/doc/pub/week44/html/._week44-bs018.html
index ef985c653..3f7c65e2a 100644
--- a/doc/pub/week44/html/._week44-bs018.html
+++ b/doc/pub/week44/html/._week44-bs018.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
- Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+ Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,52 +397,20 @@ MathJax.Hub.Config({
-
Plotting
+
A Classification Tree
-
-
-
-
So what do we have so far? We have 'picked' \( k \) centroids at random from our
-data points. There are other ways of more intelligently choosing their
-initializations, however for our purposes randomly is fine. Then we have
-initialized an array 'distances' which holds the information of the distance,
-or dissimilarity , of every point to of our centroids. Finally, we have
-initialized an array 'cluster_labels' which according to our distances array
-holds the information of to which centroid every point is assigned. This was the
-first pass of our algorithm. Essentially, all we need to do now is repeat the
-distance and assignment steps above until we have reached a desired convergence
-or a maximum amount of iterations.
+
A classification tree is very similar to a regression tree, except
+that it is used to predict a qualitative response rather than a
+quantitative one. Recall that for a regression tree, the predicted
+response for an observation is given by the mean response of the
+training observations that belong to the same terminal node. In
+contrast, for a classification tree, we predict that each observation
+belongs to the most commonly occurring class of training observations
+in the region to which it belongs. In interpreting the results of a
+classification tree, we are often interested not only in the class
+prediction corresponding to a particular terminal node region, but
+also in the class proportions among the training observations that
+fall into that region.
@@ -402,7 +438,7 @@ or a maximum amount of iterations.
27
28
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs019.html b/doc/pub/week44/html/._week44-bs019.html
index 68b3b300a..23e70c476 100644
--- a/doc/pub/week44/html/._week44-bs019.html
+++ b/doc/pub/week44/html/._week44-bs019.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,74 +397,26 @@ MathJax.Hub.Config({
-
Continuing
+
Growing a classification tree
+
The task of growing a
+classification tree is quite similar to the task of growing a
+regression tree. Just as in the regression setting, we use recursive
+binary splitting to grow a classification tree. However, in the
+classification setting, the MSE cannot be used as a criterion for making
+the binary splits. A natural alternative to MSE is the classification
+error rate . Since we plan to assign an observation in a given region
+to the most commonly occurring error rate class of training
+observations in that region, the classification error rate is simply
+the fraction of the training observations in that region that do not
+belong to the most common class.
+
-
-
-
+
When building a classification tree, either the Gini index or the
+entropy are typically used to evaluate the quality of a particular
+split, since these two approaches are more sensitive to node purity
+than is the classification error rate.
+
@@ -423,7 +443,7 @@ tolerance = 1e-
28
29
...
- 65
+ 81
»
diff --git a/doc/pub/week44/html/._week44-bs020.html b/doc/pub/week44/html/._week44-bs020.html
index 5eb6d64db..ebbe576fa 100644
--- a/doc/pub/week44/html/._week44-bs020.html
+++ b/doc/pub/week44/html/._week44-bs020.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
- Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+ Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,132 +397,47 @@ MathJax.Hub.Config({
-
Wrapping it up
-
We now have a simple , un-optimized \( k \)-means
-clustering implementation. Lets plot the final result
+
Classification tree, how to split nodes
+
+
If our targets are the outcome of a classification process that takes
+for example \( k=1,2,\dots,K \) values, the only thing we need to think of
+is to set up the splitting criteria for each node.
+
We define a PDF \( p_{mk} \) that represents the number of observations of
+a class \( k \) in a region \( R_m \) with \( N_m \) observations. We represent
+this likelihood function in terms of the proportion \( I(y_i=k) \) of
+observations of this class in the region \( R_m \) as
+
-
-
-
-
-
-
+
+ Information entropy or just entropy \( s \)
+
+$$
+s = -\sum_{k=1}^K p_{mk}\log{p_{mk}}.
+$$
@@ -482,7 +465,7 @@ plt. show()
29
30
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs021.html b/doc/pub/week44/html/._week44-bs021.html
index 2a356c79c..1aeec19f4 100644
--- a/doc/pub/week44/html/._week44-bs021.html
+++ b/doc/pub/week44/html/._week44-bs021.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,32 +397,62 @@ MathJax.Hub.Config({
-
Decision trees, overarching aims
+
Visualizing the Tree, Classification
-
We start here with the most basic algorithm, the so-called decision
-tree. With this basic algorithm we can in turn build more complex
-networks, spanning from homogeneous and heterogenous forests (bagging,
-random forests and more) to one of the most popular supervised
-algorithms nowadays, the extreme gradient boosting, or just
-XGBoost. But let us start with the simplest possible ingredient.
-
+
+
+
@@ -381,7 +479,7 @@ where we then finally end up in so called leaf nodes .
30
31
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs022.html b/doc/pub/week44/html/._week44-bs022.html
index f417ebc91..9c9e1e350 100644
--- a/doc/pub/week44/html/._week44-bs022.html
+++ b/doc/pub/week44/html/._week44-bs022.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,19 +397,53 @@ MathJax.Hub.Config({
-
Basics of a tree
+
Visualizing the Tree, The Moons
-
A decision tree is typically divided into a root node , the interior nodes ,
-and the final leaf nodes or just leaves . These entities are then connected by so-called branches .
-
+
+
-
The leaf nodes
-contain the predictions we will make for new query instances presented
-to our trained model. This is possible since the model has
-learned the underlying structure of the training data and hence can,
-given some assumptions, make predictions about the target feature value
-(class) of unseen query instances.
-
@@ -368,7 +470,7 @@ given some assumptions, make predictions about the target feature value
31
32
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs023.html b/doc/pub/week44/html/._week44-bs023.html
index 2b7563ad9..9201acde1 100644
--- a/doc/pub/week44/html/._week44-bs023.html
+++ b/doc/pub/week44/html/._week44-bs023.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,9 +397,39 @@ MathJax.Hub.Config({
-
A Sketch of a Tree, Regression problem
+
Other ways of visualizing the trees
+
+
Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.
+
+
+
+
-
@@ -358,7 +456,7 @@ MathJax.Hub.Config({
32
33
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs024.html b/doc/pub/week44/html/._week44-bs024.html
index 5b204891a..5162f403f 100644
--- a/doc/pub/week44/html/._week44-bs024.html
+++ b/doc/pub/week44/html/._week44-bs024.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,9 +397,42 @@ MathJax.Hub.Config({
-
A Sketch of a Tree, Classification problem
+
Printing out as text
+
+
Alternatively, the tree can also be exported in textual format with the function exporttext.
+This method doesn’t require the installation of external libraries and is more compact:
+
+
+
+
+
-
@@ -358,7 +459,7 @@ MathJax.Hub.Config({
33
34
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs025.html b/doc/pub/week44/html/._week44-bs025.html
index 969c7010a..337c15367 100644
--- a/doc/pub/week44/html/._week44-bs025.html
+++ b/doc/pub/week44/html/._week44-bs025.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,15 +397,18 @@ MathJax.Hub.Config({
-
A typical Decision Tree with its pertinent Jargon, Classification Problem
+
Algorithms for Setting up Decision Trees
-
-
-
-
-
-
-
This tree was produced using the Wisconsin cancer data (discussed here as well, see code examples below) using Scikit-Learn 's decision tree classifier. Here we have used the so-called gini index (see below) to split the various branches.
+
Two algorithms stand out in the set up of decision trees:
+
+ The CART (Classification And Regression Tree) algorithm for both classification and regression
+ The ID3 algorithm based on the computation of the information gain for classification
+
+
We discuss both algorithms with applications here. The popular library
+Scikit-Learn uses the CART algorithm. For classification problems
+you can use either the gini index or the entropy to split a tree
+in two branches.
+
@@ -364,7 +435,7 @@ MathJax.Hub.Config({
34
35
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs026.html b/doc/pub/week44/html/._week44-bs026.html
index 0b4c3c9ea..cb92dbb94 100644
--- a/doc/pub/week44/html/._week44-bs026.html
+++ b/doc/pub/week44/html/._week44-bs026.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,18 +397,29 @@ MathJax.Hub.Config({
-
General Features
+
The CART algorithm for Classification
-
The overarching approach to decision trees is a top-down approach.
+
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
+This could be for example a threshold set by a number below a certain circumference of a malign tumor.
+
-
- A leaf provides the classification of a given instance.
- A node specifies a test of some attribute of the instance.
- A branch corresponds to a possible values of an attribute.
- An instance is classified by starting at the root node of the tree, testing the attribute specified by this node, then moving down the tree branch corresponding to the value of the attribute in the given example.
-
-
This process is then repeated for the subtree rooted at the new
-node.
+
How do we find these two quantities?
+We search for the pair \( (k,t_k) \) that produces the purest subset using for example the gini factor \( G \).
+The cost function it tries to minimize is then
+
+$$
+C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}},
+$$
+
+
where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \)
+ is the number of instances in the left/right subset
+
+
+
Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets
+and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the
+\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other
+hyperparameters control additional stopping conditions such as the \( min\_samples\_split \),
+\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).
@@ -368,7 +447,7 @@ node.
35
36
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs027.html b/doc/pub/week44/html/._week44-bs027.html
index 4110ab149..09c18f5b6 100644
--- a/doc/pub/week44/html/._week44-bs027.html
+++ b/doc/pub/week44/html/._week44-bs027.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,19 +397,30 @@ MathJax.Hub.Config({
-
How do we set it up?
+
The CART algorithm for Regression
-
In simplified terms, the process of training a decision tree and
-predicting the target features of query instances is as follows:
+
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
+training set in a way that minimizes say the gini or entropy impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now
+$$
+C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}.
+$$
-
- Present a dataset containing of a number of training instances characterized by a number of descriptive features and a target feature
- Train the decision tree model by continuously splitting the target feature along the values of the descriptive features using a measure of information gain during the training process
- Grow the tree until we accomplish a stopping criteria create leaf nodes which represent the predictions we want to make for new query instances
- Show query instances to the tree and run down the tree until we arrive at leaf nodes
-
-
Then we are essentially done!
+
Here the MSE for a specific node is defined as
+$$
+\mathrm{MSE}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}(\overline{y}_{\mathrm{node}}-y_i)^2,
+$$
+
+
with
+$$
+\overline{y}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}y_i,
+$$
+
+
the mean value of all observations in a specific node.
+
+
Without any regularization, the regression task for decision trees,
+just like for classification tasks, is prone to overfitting.
+
@@ -368,7 +447,7 @@ predicting the target features of query instances is as follows:
36
37
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs028.html b/doc/pub/week44/html/._week44-bs028.html
index 8dcf1996a..91df74bdf 100644
--- a/doc/pub/week44/html/._week44-bs028.html
+++ b/doc/pub/week44/html/._week44-bs028.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,117 +397,46 @@ MathJax.Hub.Config({
-
Decision trees and Regression
+
Computing the Gini index
-
-
+
The example we will look at is a classical one in many Machine
+Learning applications. Based on various meteorological features, we
+have several so-called attributes which decide whether we at the end
+will do some outdoor activity like skiing, going for a bike ride etc
+etc. The table here contains the feautures outlook , temperature ,
+humidity and wind . The target or output is whether we ride
+(True=1) or whether we do something else that day (False=0). The
+attributes for each feature are then sunny, overcast and rain for the
+outlook, hot, cold and mild for temperature, high and normal for
+humidity and weak and strong for wind.
+
+
The table here summarizes the various attributes and
+
+
+
+
+Day Outlook Temperature Humidity Wind Ride
+
+
+ 1 Sunny Hot High Weak 0
+ 2 Sunny Hot High Strong 1
+ 3 Overcast Hot High Weak 1
+ 4 Rain Mild High Weak 1
+ 5 Rain Cool Normal Weak 1
+ 6 Rain Cool Normal Strong 0
+ 7 Overcast Cool Normal Strong 1
+ 8 Sunny Mild High Weak 0
+ 9 Sunny Cool Normal Weak 1
+ 10 Rain Mild Normal Weak 1
+ 11 Sunny Mild Normal Strong 1
+ 12 Overcast Mild High Strong 1
+ 13 Overcast Hot Normal Weak 1
+ 14 Rain Mild High Strong 0
+
+
+
+
@@ -466,7 +463,7 @@ plt. show()
37
38
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs029.html b/doc/pub/week44/html/._week44-bs029.html
index bbcd4c231..453817e85 100644
--- a/doc/pub/week44/html/._week44-bs029.html
+++ b/doc/pub/week44/html/._week44-bs029.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,28 +397,97 @@ MathJax.Hub.Config({
-
Building a tree, regression
+
-
There are mainly two steps
-
- We split the predictor space (the set of possible values \( x_1,x_2,\dots, x_p \)) into \( J \) distinct and non-non-overlapping regions, \( R_1,R_2,\dots,R_J \).
- For every observation that falls into the region \( R_j \) , we make the same prediction, which is simply the mean of the response values for the training observations in \( R_j \).
-
-
How do we construct the regions \( R_1,\dots,R_J \)? In theory, the
-regions could have any shape. However, we choose to divide the
-predictor space into high-dimensional rectangles, or boxes, for
-simplicity and for ease of interpretation of the resulting predictive
-model. The goal is to find boxes \( R_1,\dots,R_J \) that minimize the
-MSE, given by
-
-$$
-\sum_{j=1}^J\sum_{i\in R_j}(y_i-\overline{y}_{R_j})^2,
-$$
+
+
-
where \( \overline{y}_{R_j} \) is the mean response for the training observations
-within box \( j \).
-
@@ -377,7 +514,7 @@ within box \( j \).
38
39
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs030.html b/doc/pub/week44/html/._week44-bs030.html
index 513fcac5e..19732afd8 100644
--- a/doc/pub/week44/html/._week44-bs030.html
+++ b/doc/pub/week44/html/._week44-bs030.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,21 +397,98 @@ MathJax.Hub.Config({
-
A top-down approach, recursive binary splitting
+
Computing the Gini Factor
-
Unfortunately, it is computationally infeasible to consider every
-possible partition of the feature space into \( J \) boxes. The common
-strategy is to take a top-down approach
+
The above functions (gini, entropy and misclassification error) are
+important components of the so-called CART algorithm. We will discuss
+this algorithm below after we have discussed the information gain
+algorithm ID3.
-
The approach is top-down because it begins at the top of the tree (all
-observations belong to a single region) and then successively splits
-the predictor space; each split is indicated via two new branches
-further down on the tree. It is greedy because at each step of the
-tree-building process, the best split is made at that particular step,
-rather than looking ahead and picking a split that will lead to a
-better tree in some future step.
-
+
In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.
+
+
+
+
+
@@ -370,7 +515,7 @@ better tree in some future step.
39
40
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs031.html b/doc/pub/week44/html/._week44-bs031.html
index 67513b5b4..e11aa27ec 100644
--- a/doc/pub/week44/html/._week44-bs031.html
+++ b/doc/pub/week44/html/._week44-bs031.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,52 +397,36 @@ MathJax.Hub.Config({
-
Making a tree
+
Entropy and the ID3 algorithm
-
In order to implement the recursive binary splitting we start by selecting
-the predictor \( x_j \) and a cutpoint \( s \) that splits the predictor space into two regions \( R_1 \) and \( R_2 \)
-
-$$
-\left\{X\vert x_j < s\right\},
-$$
-
-
and
-$$
-\left\{X\vert x_j \geq s\right\},
-$$
-
-
so that we obtain the lowest MSE, that is
-$$
-\sum_{i:x_i\in R_j}(y_i-\overline{y}_{R_1})^2+\sum_{i:x_i\in R_2}(y_i-\overline{y}_{R_2})^2,
-$$
-
-
which we want to minimize by considering all predictors
-\( x_1,x_2,\dots,x_p \). We consider also all possible values of \( s \) for
-each predictor. These values could be determined by randomly assigned
-numbers or by starting at the midpoint and then proceed till we find
-an optimal value.
+
The ID3 algorithm learns decision trees by constructing
+them in a top down way, beginning with the question which attribute should be tested at the root of the tree ?
-
For any \( j \) and \( s \), we define the pair of half-planes where
-\( \overline{y}_{R_1} \) is the mean response for the training
-observations in \( R_1(j,s) \), and \( \overline{y}_{R_2} \) is the mean
-response for the training observations in \( R_2(j,s) \).
+
+ Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.
+ The best attribute is selected and used as the test at the root node of the tree.
+ A descendant of the root node is then created for each possible value of this attribute.
+ Training examples are sorted to the appropriate descendant node.
+ The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.
+ This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.
+
+
The ID3 algorithm selects which attribute to test at each node in the
+tree.
-
Finding the values of \( j \) and \( s \) that minimize the above equation can be
-done quite quickly, especially when the number of features \( p \) is not
-too large.
+
We would like to select the attribute that is most useful for classifying
+examples.
-
Next, we repeat the process, looking
-for the best predictor and best cutpoint in order to split the data
-further so as to minimize the MSE within each of the resulting
-regions. However, this time, instead of splitting the entire predictor
-space, we split one of the two previously identified regions. We now
-have three regions. Again, we look to split one of these three regions
-further, so as to minimize the MSE. The process continues until a
-stopping criterion is reached; for instance, we may continue until no
-region contains more than five observations.
+
What is a good quantitative measure of the worth of an attribute?
+
+
Information gain measures how well a given attribute separates the
+training examples according to their target classification.
+
+
+
The ID3 algorithm uses this information gain measure to select among the candidate
+attributes at each step while growing the tree.
@@ -402,7 +454,7 @@ region contains more than five observations.
40
41
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs032.html b/doc/pub/week44/html/._week44-bs032.html
index 22155055b..de7edf322 100644
--- a/doc/pub/week44/html/._week44-bs032.html
+++ b/doc/pub/week44/html/._week44-bs032.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -328,24 +396,71 @@ MathJax.Hub.Config({
-
-
Pruning the tree
+
+
Cancer Data again now with Decision Trees and other Methods
-
The above procedure is rather straightforward, but leads often to
-overfitting and unnecessarily large and complicated trees. The basic
-idea is to grow a large tree \( T_0 \) and then prune it back in order to
-obtain a subtree. A smaller tree with fewer splits (fewer regions) can
-lead to smaller variance and better interpretation at the cost of a
-little more bias.
-
+
+
-
Read more at the following Scikit-Learn link on pruning .
@@ -372,7 +487,7 @@ parameter \( \alpha \).
41
42
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs033.html b/doc/pub/week44/html/._week44-bs033.html
index 6d98fe296..8a74e4421 100644
--- a/doc/pub/week44/html/._week44-bs033.html
+++ b/doc/pub/week44/html/._week44-bs033.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,35 +397,93 @@ MathJax.Hub.Config({
-
Cost complexity pruning
+
Another example, the moons again
-
For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that
-$$
-\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T},
-$$
+
+
-
It turns out that as we increase \( \alpha \) from zero
-branches get pruned from the tree in a nested and predictable fashion,
-so obtaining the whole sequence of subtrees as a function of \( \alpha \) is
-easy. We can select a value of \( \alpha \) using a validation set or using
-cross-validation. We then return to the full data set and obtain the
-subtree corresponding to \( \alpha \).
-
@@ -384,7 +510,7 @@ subtree corresponding to \( \alpha \).
42
43
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs034.html b/doc/pub/week44/html/._week44-bs034.html
index 92883cb83..815237ab5 100644
--- a/doc/pub/week44/html/._week44-bs034.html
+++ b/doc/pub/week44/html/._week44-bs034.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,24 +397,47 @@ MathJax.Hub.Config({
-
Schematic Regression Procedure
+
Playing around with regions
-
-
-
+
+
@@ -375,7 +466,7 @@ MathJax.Hub.Config({
43
44
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs035.html b/doc/pub/week44/html/._week44-bs035.html
index ab11a9ac9..3f90d128b 100644
--- a/doc/pub/week44/html/._week44-bs035.html
+++ b/doc/pub/week44/html/._week44-bs035.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,21 +397,58 @@ MathJax.Hub.Config({
-
A Classification Tree
+
Regression trees
+
+
+
+
+
+
+
-
A classification tree is very similar to a regression tree, except
-that it is used to predict a qualitative response rather than a
-quantitative one. Recall that for a regression tree, the predicted
-response for an observation is given by the mean response of the
-training observations that belong to the same terminal node. In
-contrast, for a classification tree, we predict that each observation
-belongs to the most commonly occurring class of training observations
-in the region to which it belongs. In interpreting the results of a
-classification tree, we are often interested not only in the class
-prediction corresponding to a particular terminal node region, but
-also in the class proportions among the training observations that
-fall into that region.
-
@@ -370,7 +475,7 @@ fall into that region.
44
45
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs036.html b/doc/pub/week44/html/._week44-bs036.html
index 94b8b3633..5f2c788bb 100644
--- a/doc/pub/week44/html/._week44-bs036.html
+++ b/doc/pub/week44/html/._week44-bs036.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,26 +397,114 @@ MathJax.Hub.Config({
-
Growing a classification tree
+
Final regressor code
-
The task of growing a
-classification tree is quite similar to the task of growing a
-regression tree. Just as in the regression setting, we use recursive
-binary splitting to grow a classification tree. However, in the
-classification setting, the MSE cannot be used as a criterion for making
-the binary splits. A natural alternative to MSE is the classification
-error rate . Since we plan to assign an observation in a given region
-to the most commonly occurring error rate class of training
-observations in that region, the classification error rate is simply
-the fraction of the training observations in that region that do not
-belong to the most common class.
-
+
+
+
+
+
+
-
When building a classification tree, either the Gini index or the
-entropy are typically used to evaluate the quality of a particular
-split, since these two approaches are more sensitive to node purity
-than is the classification error rate.
-
@@ -375,7 +531,7 @@ than is the classification error rate.
45
46
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs037.html b/doc/pub/week44/html/._week44-bs037.html
index d2a29a83b..9ff52983c 100644
--- a/doc/pub/week44/html/._week44-bs037.html
+++ b/doc/pub/week44/html/._week44-bs037.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,49 +397,17 @@ MathJax.Hub.Config({
-
Classification tree, how to split nodes
-
-
If our targets are the outcome of a classification process that takes
-for example \( k=1,2,\dots,K \) values, the only thing we need to think of
-is to set up the splitting criteria for each node.
-
-
-
We define a PDF \( p_{mk} \) that represents the number of observations of
-a class \( k \) in a region \( R_m \) with \( N_m \) observations. We represent
-this likelihood function in terms of the proportion \( I(y_i=k) \) of
-observations of this class in the region \( R_m \) as
-
-
-$$
-p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i=k).
-$$
-
-
We let \( p_{mk} \) represent the majority class of observations in region
-\( m \). The three most common ways of splitting a node are given by
-
+
Pros and cons of trees, pros
- Misclassification error
+ White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)
+ Trees are very easy to explain to people. In fact, they are even easier to explain than linear regression!
+ No feature normalization needed
+ Tree models can handle both continuous and categorical data (Classification and Regression Trees)
+ Can model nonlinear relationships
+ Can model interactions between the different descriptive features
+ Trees can be displayed graphically, and are easily interpreted even by a non-expert (especially if they are small)
-$$
-p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i\ne k) = 1-p_{mk}.
-$$
-
-
-$$
-g = \sum_{k=1}^K p_{mk}(1-p_{mk}).
-$$
-
-
- Information entropy or just entropy \( s \)
-
-$$
-s = -\sum_{k=1}^K p_{mk}\log{p_{mk}}.
-$$
-
-
diff --git a/doc/pub/week44/html/._week44-bs038.html b/doc/pub/week44/html/._week44-bs038.html
index 7dd197baa..e48cdf42c 100644
--- a/doc/pub/week44/html/._week44-bs038.html
+++ b/doc/pub/week44/html/._week44-bs038.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,62 +397,21 @@ MathJax.Hub.Config({
-
Visualizing the Tree, Classification
-
-
-
+
Disadvantages
+
+ Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches
+ If continuous features are used the tree may become quite large and hence less interpretable
+ Decision trees are prone to overfit the training data and hence do not well generalize the data if no stopping criteria or improvements like pruning, boosting or bagging are implemented
+ Small changes in the data may lead to a completely different tree. This issue can be addressed by using ensemble methods like bagging, boosting or random forests
+ Unbalanced datasets where some target feature values occur much more frequently than others may lead to biased trees since the frequently occurring feature values are preferred over the less frequently occurring ones.
+ If the number of features is relatively large (high dimensional) and the number of instances is relatively low, the tree might overfit the data
+ Features with many levels may be preferred over features with less levels since for them it is more easy to split the dataset such that the sub datasets only contain pure target feature values. This issue can be addressed by preferring for instance the information gain ratio as splitting criteria over information gain
+
+
However, by aggregating many decision trees, using methods like
+bagging, random forests, and boosting, the predictive performance of
+trees can be substantially improved.
+
@@ -411,7 +438,7 @@ os. system(cmd)
47
48
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs039.html b/doc/pub/week44/html/._week44-bs039.html
index a37cfca96..5e5a6e986 100644
--- a/doc/pub/week44/html/._week44-bs039.html
+++ b/doc/pub/week44/html/._week44-bs039.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,53 +397,28 @@ MathJax.Hub.Config({
-
Visualizing the Tree, The Moons
+
Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
-
-
+
This leads us to a set of different methods that can combine different
+machine learning algorithms or just use one of them to construct
+forests and jungles of trees, homogeneous ones or heterogenous
+ones. These methods are recognized by different names which we will
+try to explain here. These are
+
+
+ Voting classifiers
+ Bagging and Pasting
+ Random forests
+ Boosting methods, from adaptive to Extreme Gradient Boosting (XGBoost)
+
+
We discuss these methods here.
@@ -402,7 +445,7 @@ os. system(cmd)
48
49
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs040.html b/doc/pub/week44/html/._week44-bs040.html
index eaa8c9516..4ee3da16d 100644
--- a/doc/pub/week44/html/._week44-bs040.html
+++ b/doc/pub/week44/html/._week44-bs040.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,39 +397,13 @@ MathJax.Hub.Config({
-
Other ways of visualizing the trees
-
-
Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.
-
-
-
-
+
An Overview of Ensemble Methods
+
+
+
+
+
@@ -388,7 +430,7 @@ tree. plot_tree(tree_clf)
49
50
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs041.html b/doc/pub/week44/html/._week44-bs041.html
index 5eabb692b..ad70501f7 100644
--- a/doc/pub/week44/html/._week44-bs041.html
+++ b/doc/pub/week44/html/._week44-bs041.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,42 +397,21 @@ MathJax.Hub.Config({
-
Printing out as text
+
Bagging
-
Alternatively, the tree can also be exported in textual format with the function exporttext.
-This method doesn’t require the installation of external libraries and is more compact:
+
The plain decision trees suffer from high
+variance. This means that if we split the training data into two parts
+at random, and fit a decision tree to both halves, the results that we
+get could be quite different. In contrast, a procedure with low
+variance will yield similar results if applied repeatedly to distinct
+data sets; linear regression tends to have low variance, if the ratio
+of \( n \) to \( p \) is moderately large.
-
-
-
-
+
Bootstrap aggregation , or just bagging , is a
+general-purpose procedure for reducing the variance of a statistical
+learning method.
+
@@ -391,7 +438,7 @@ r = export_text(decision_tree, feature_names
50
51
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs042.html b/doc/pub/week44/html/._week44-bs042.html
index f2b6ca4e6..f733f2a2f 100644
--- a/doc/pub/week44/html/._week44-bs042.html
+++ b/doc/pub/week44/html/._week44-bs042.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,17 +397,30 @@ MathJax.Hub.Config({
-
Algorithms for Setting up Decision Trees
+
More bagging
-
Two algorithms stand out in the set up of decision trees:
-
- The CART (Classification And Regression Tree) algorithm for both classification and regression
- The ID3 algorithm based on the computation of the information gain for classification
-
-
We discuss both algorithms with applications here. The popular library
-Scikit-Learn uses the CART algorithm. For classification problems
-you can use either the gini index or the entropy to split a tree
-in two branches.
+
Bagging typically results in improved accuracy
+over prediction using a single tree. Unfortunately, however, it can be
+difficult to interpret the resulting model. Recall that one of the
+advantages of decision trees is the attractive and easily interpreted
+diagram that results.
+
+
+
However, when we bag a large number of trees, it is no longer
+possible to represent the resulting statistical learning procedure
+using a single tree, and it is no longer clear which variables are
+most important to the procedure. Thus, bagging improves prediction
+accuracy at the expense of interpretability. Although the collection
+of bagged trees is much more difficult to interpret than a single
+tree, one can obtain an overall summary of the importance of each
+predictor using the MSE (for bagging regression trees) or the Gini
+index (for bagging classification trees). In the case of bagging
+regression trees, we can record the total amount that the MSE is
+decreased due to splits over a given predictor, averaged over all \( B \) possible
+trees. A large value indicates an important predictor. Similarly, in
+the context of bagging classification trees, we can add up the total
+amount that the Gini index is decreased by splits over a given
+predictor, averaged over all \( B \) trees.
@@ -367,7 +448,7 @@ in two branches.
51
52
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs043.html b/doc/pub/week44/html/._week44-bs043.html
index 410623d60..32d9461b8 100644
--- a/doc/pub/week44/html/._week44-bs043.html
+++ b/doc/pub/week44/html/._week44-bs043.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,30 +397,42 @@ MathJax.Hub.Config({
-
The CART algorithm for Classification
+
Simple Voting Example, head or tail
-
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
-This could be for example a threshold set by a number below a certain circumference of a malign tumor.
-
+
+
-
How do we find these two quantities?
-We search for the pair \( (k,t_k) \) that produces the purest subset using for example the gini factor \( G \).
-The cost function it tries to minimize is then
-
-$$
-C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}},
-$$
-
-
where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \)
- is the number of instances in the left/right subset
-
-
-
Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets
-and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the
-\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other
-hyperparameters control additional stopping conditions such as the \( min\_samples\_split \),
-\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).
-
@@ -379,7 +459,7 @@ hyperparameters control additional stopping conditions such as the \( min\_sampl
52
53
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs044.html b/doc/pub/week44/html/._week44-bs044.html
index 0d0c97d09..799c8463e 100644
--- a/doc/pub/week44/html/._week44-bs044.html
+++ b/doc/pub/week44/html/._week44-bs044.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,30 +397,72 @@ MathJax.Hub.Config({
-
The CART algorithm for Regression
+
Using the Voting Classifier
-
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
-training set in a way that minimizes say the gini or entropy impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now
-
-$$
-C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}.
-$$
+
+
-
Without any regularization, the regression task for decision trees,
-just like for classification tasks, is prone to overfitting.
-
@@ -379,7 +489,7 @@ just like for classification tasks, is prone to overfitting.
53
54
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs045.html b/doc/pub/week44/html/._week44-bs045.html
index 2b485d9e3..c48d437ba 100644
--- a/doc/pub/week44/html/._week44-bs045.html
+++ b/doc/pub/week44/html/._week44-bs045.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,46 +397,125 @@ MathJax.Hub.Config({
-
Computing the Gini index
+
Please, not the moons again! Voting and Bagging
-
The example we will look at is a classical one in many Machine
-Learning applications. Based on various meteorological features, we
-have several so-called attributes which decide whether we at the end
-will do some outdoor activity like skiing, going for a bike ride etc
-etc. The table here contains the feautures outlook , temperature ,
-humidity and wind . The target or output is whether we ride
-(True=1) or whether we do something else that day (False=0). The
-attributes for each feature are then sunny, overcast and rain for the
-outlook, hot, cold and mild for temperature, high and normal for
-humidity and weak and strong for wind.
-
-
The table here summarizes the various attributes and
-
-
-
-
-Day Outlook Temperature Humidity Wind Ride
-
-
- 1 Sunny Hot High Weak 0
- 2 Sunny Hot High Strong 1
- 3 Overcast Hot High Weak 1
- 4 Rain Mild High Weak 1
- 5 Rain Cool Normal Weak 1
- 6 Rain Cool Normal Strong 0
- 7 Overcast Cool Normal Strong 1
- 8 Sunny Mild High Weak 0
- 9 Sunny Cool Normal Weak 1
- 10 Rain Mild Normal Weak 1
- 11 Sunny Mild Normal Strong 1
- 12 Overcast Mild High Strong 1
- 13 Overcast Hot Normal Weak 1
- 14 Rain Mild High Strong 0
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -395,7 +542,7 @@ humidity and weak and strong for wind.
54
55
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs046.html b/doc/pub/week44/html/._week44-bs046.html
index 8c11fa877..b2317f60c 100644
--- a/doc/pub/week44/html/._week44-bs046.html
+++ b/doc/pub/week44/html/._week44-bs046.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,7 +397,7 @@ MathJax.Hub.Config({
-
+
Bagging Examples
@@ -338,73 +406,104 @@ MathJax.Hub.Config({
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -446,7 +545,7 @@ os
. system(cmd)
55
56
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs047.html b/doc/pub/week44/html/._week44-bs047.html
index d9ccf27fa..e0ec9c966 100644
--- a/doc/pub/week44/html/._week44-bs047.html
+++ b/doc/pub/week44/html/._week44-bs047.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,83 +397,75 @@ MathJax.Hub.Config({
-
Computing the Gini Factor
+
Making your own Bootstrap: Changing the Level of the Decision Tree
-
The above functions (gini, entropy and misclassification error) are
-important components of the so-called CART algorithm. We will discuss
-this algorithm below after we have discussed the information gain
-algorithm ID3.
+
Let us bring up our good old boostrap example from the linear regression lectures. We change the linerar regression algorithm with
+a decision tree wth different depths and perform a bootstrap aggregate (in this case we perform as many bootstraps as data points \( n \)).
-
In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.
-
-
-
# Split a dataset based on an attribute and an attribute value
-def test_split (index, value, dataset):
- left, right = list (), list ()
- for row in dataset:
- if row[index] < value:
- left. append(row)
- else :
- right. append(row)
- return left, right
-
-# Calculate the Gini index for a split dataset
-def gini_index (groups, classes):
- # count all samples at split point
- n_instances = float (sum ([len (group) for group in groups]))
- # sum weighted Gini index for each group
- gini = 0.0
- for group in groups:
- size = float (len (group))
- # avoid divide by zero
- if size == 0 :
- continue
- score = 0.0
- # score the group based on the score for each class
- for class_val in classes:
- p = [row[-1 ] for row in group]. count(class_val) / size
- score += p * p
- # weight the group score by its relative size
- gini += (1.0 - score) * (size / n_instances)
- return gini
+ import matplotlib.pyplot as plt
+import numpy as np
+from sklearn.model_selection import train_test_split
+from sklearn.pipeline import make_pipeline
+from sklearn.utils import resample
+from sklearn.tree import DecisionTreeRegressor
-# Select the best split point for a dataset
-def get_split (dataset):
- class_values = list (set (row[-1 ] for row in dataset))
- b_index, b_value, b_score, b_groups = 999 , 999 , 999 , None
- for index in range (len (dataset[0 ])-1 ):
- for row in dataset:
- groups = test_split(index, row[index], dataset)
- gini = gini_index(groups, class_values)
- print ('X %d < %.3f Gini= %.3f ' % ((index+1 ), row[index], gini))
- if gini < b_score:
- b_index, b_value, b_score, b_groups = index, row[index], gini, groups
- return {'index' :b_index, 'value' :b_value, 'groups' :b_groups}
-
-dataset = [[0 ,0 ,0 ,0 ,0 ],
- [0 ,0 ,0 ,1 ,1 ],
- [1 ,0 ,0 ,0 ,1 ],
- [2 ,1 ,0 ,0 ,1 ],
- [2 ,2 ,1 ,0 ,1 ],
- [2 ,2 ,1 ,1 ,0 ],
- [1 ,2 ,1 ,1 ,1 ],
- [0 ,1 ,0 ,0 ,0 ],
- [0 ,2 ,1 ,0 ,1 ],
- [2 ,1 ,1 ,0 ,1 ],
- [0 ,1 ,1 ,1 ,1 ],
- [1 ,1 ,0 ,1 ,1 ],
- [1 ,0 ,1 ,0 ,1 ],
- [2 ,1 ,0 ,1 ,0 ]]
+n = 100
+n_boostraps = 100
+maxdepth = 8
-split = get_split(dataset)
-print ('Split: [X %d < %.3f ]' % ((split['index' ]+1 ), split['value' ]))
+# Make data set.
+x = np. linspace(-3 , 3 , n). reshape(-1 , 1 )
+y = np. exp(- x**2 ) + 1.5 * np. exp(- (x-2 )**2 )+ np. random. normal(0 , 0.1 , x. shape)
+error = np. zeros(maxdepth)
+bias = np. zeros(maxdepth)
+variance = np. zeros(maxdepth)
+polydegree = np. zeros(maxdepth)
+X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2 )
+
+from sklearn.preprocessing import StandardScaler
+scaler = StandardScaler()
+scaler. fit(X_train)
+X_train_scaled = scaler. transform(X_train)
+X_test_scaled = scaler. transform(X_test)
+
+# we produce a simple tree first as benchmark
+simpletree = DecisionTreeRegressor(max_depth=3 )
+simpletree. fit(X_train_scaled, y_train)
+simpleprediction = simpletree. predict(X_test_scaled)
+for degree in range (1 ,maxdepth):
+ model = DecisionTreeRegressor(max_depth= degree)
+ y_pred = np. empty((y_test. shape[0 ], n_boostraps))
+ for i in range (n_boostraps):
+ x_, y_ = resample(X_train_scaled, y_train)
+ model. fit(x_, y_)
+ y_pred[:, i] = model. predict(X_test_scaled)#.ravel()
+
+ polydegree[degree] = degree
+ error[degree] = np. mean( np. mean((y_test - y_pred)**2 , axis=1 , keepdims= True ) )
+ bias[degree] = np. mean( (y_test - np. mean(y_pred, axis=1 , keepdims= True ))**2 )
+ variance[degree] = np. mean( np. var(y_pred, axis=1 , keepdims= True ) )
+ print ('Polynomial degree:' , degree)
+ print ('Error:' , error[degree])
+ print ('Bias^2:' , bias[degree])
+ print ('Var:' , variance[degree])
+ print (' {} >= {} + {} = {} ' . format(error[degree], bias[degree], variance[degree], bias[degree]+ variance[degree]))
+
+mse_simpletree= np. mean( np. mean((y_test - simpleprediction)**2 )
+print (mse_simpletree)
+plt. xlim(1 ,maxdepth)
+plt. plot(polydegree, error, label= 'MSE' )
+plt. plot(polydegree, bias, label= 'bias' )
+plt. plot(polydegree, variance, label= 'Variance' )
+plt. legend()
+save_fig("baggingboot" )
+plt. show()
@@ -447,7 +507,7 @@ split
= get_split(dataset)
56
57
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs048.html b/doc/pub/week44/html/._week44-bs048.html
index 64eac63f0..fec431750 100644
--- a/doc/pub/week44/html/._week44-bs048.html
+++ b/doc/pub/week44/html/._week44-bs048.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,36 +397,12 @@ MathJax.Hub.Config({
-
Entropy and the ID3 algorithm
+
Why binary splits?
-
The ID3 algorithm learns decision trees by constructing
-them in a top down way, beginning with the question which attribute should be tested at the root of the tree ?
-
-
-
- Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.
- The best attribute is selected and used as the test at the root node of the tree.
- A descendant of the root node is then created for each possible value of this attribute.
- Training examples are sorted to the appropriate descendant node.
- The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.
- This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.
-
-
The ID3 algorithm selects which attribute to test at each node in the
-tree.
-
-
-
We would like to select the attribute that is most useful for classifying
-examples.
-
-
-
What is a good quantitative measure of the worth of an attribute?
-
-
Information gain measures how well a given attribute separates the
-training examples according to their target classification.
-
-
-
The ID3 algorithm uses this information gain measure to select among the candidate
-attributes at each step while growing the tree.
+
It is custom to split to a tree uising binary splits. The reason is
+that multiway splits fragment the data too quickly, leaving
+insufficient data at the next level down. Multiway splits can be
+achieved by a series of binary split and this is normally preferred.
@@ -386,7 +430,7 @@ attributes at each step while growing the tree.
57
58
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs049.html b/doc/pub/week44/html/._week44-bs049.html
index 6d6bf601c..70ed4f4a1 100644
--- a/doc/pub/week44/html/._week44-bs049.html
+++ b/doc/pub/week44/html/._week44-bs049.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,71 +397,23 @@ MathJax.Hub.Config({
-
Cancer Data again now with Decision Trees and other Methods
-
-
-
+
Computing a Tree using the Gini Index
+
Consider the following example with attributes/features and two
+possible outcomes (classes) for each attribute. Assume we wish to find some
+correlations between the average grade of a student as function of the
+number of hours studied and hours slept. We want also to correlate the
+grade in a given course with the general trend, whether the students
+recently has gotten grades below average or above.
+
+
We have three features/attributes
+
+ Trend of average grades before present course, classified as either below or above the average grade of the whole class
+ The number of hours studies, classified again as either higher (more than 3 hours per day) or lower . Here we have used a standard for one \( ECTS \) which is scaled to 25-30 hours of work for a semester which lasts 18 weeks, with 15 weeks of lectures and 3 weeks for exams, assuming a total of 30 ECTS per semester.
+ The number of hours slept as high for more than \( 8 \) hours and below for less than 8 hours of sleep, classified again as either high or low
+ The final grade whether it is above or below average
+
diff --git a/doc/pub/week44/html/._week44-bs050.html b/doc/pub/week44/html/._week44-bs050.html
index 06d973914..c3dd07d40 100644
--- a/doc/pub/week44/html/._week44-bs050.html
+++ b/doc/pub/week44/html/._week44-bs050.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,93 +397,29 @@ MathJax.Hub.Config({
-
Another example, the moons again
-
-
-
+
The Table
+
+
+
+
+Grade Trend Hours slept Hours Studied Grade
+
+
+ Above Low High Above
+ Below High Low Below
+ Above Low High Above
+ Above High High Above
+ Below Low High Below
+ Above Low Low Below
+ Below High High Below
+ Below Low High Below
+ Above Low Low Below
+ Above High High Above
+
+
+
+
@@ -442,7 +446,7 @@ plt. show()
59
60
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs051.html b/doc/pub/week44/html/._week44-bs051.html
index 698e00993..1db44b1e0 100644
--- a/doc/pub/week44/html/._week44-bs051.html
+++ b/doc/pub/week44/html/._week44-bs051.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,47 +397,17 @@ MathJax.Hub.Config({
-
Playing around with regions
+
Computing the various Gini Indices
-
-
-
-
@@ -398,7 +436,7 @@ plt
. show()
60
61
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs052.html b/doc/pub/week44/html/._week44-bs052.html
index ecc52c78e..c1d4b6484 100644
--- a/doc/pub/week44/html/._week44-bs052.html
+++ b/doc/pub/week44/html/._week44-bs052.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,56 +397,13 @@ MathJax.Hub.Config({
-
Regression trees
+
Computing the various Gini Indices, Hours slept
-
-
-
-
-
-
-
-
@@ -407,7 +432,7 @@ tree_reg
. fit(X, y)
61
62
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs053.html b/doc/pub/week44/html/._week44-bs053.html
index 86a1d8700..41127e1f8 100644
--- a/doc/pub/week44/html/._week44-bs053.html
+++ b/doc/pub/week44/html/._week44-bs053.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,115 +397,18 @@ MathJax.Hub.Config({
-
Final regressor code
+
Computing the various Gini Indices, Hours studied
-
-
-
-
-
-
-
-
+
For final tree, see the above handwritten notes
+
diff --git a/doc/pub/week44/html/._week44-bs054.html b/doc/pub/week44/html/._week44-bs054.html
index d029f14aa..d4fca77eb 100644
--- a/doc/pub/week44/html/._week44-bs054.html
+++ b/doc/pub/week44/html/._week44-bs054.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,17 +397,98 @@ MathJax.Hub.Config({
-
Pros and cons of trees, pros
+
A possible code using Scikit-Learn
+
+
+
+
+
-
- White box, easy to interpret model. Some people believe that decision trees more closely mirror human decision-making than do the regression and classification approaches discussed earlier (think of support vector machines)
- Trees are very easy to explain to people. In fact, they are even easier to explain than linear regression!
- No feature normalization needed
- Tree models can handle both continuous and categorical data (Classification and Regression Trees)
- Can model nonlinear relationships
- Can model interactions between the different descriptive features
- Trees can be displayed graphically, and are easily interpreted even by a non-expert (especially if they are small)
-
diff --git a/doc/pub/week44/html/._week44-bs055.html b/doc/pub/week44/html/._week44-bs055.html
index 56f68a610..861521fed 100644
--- a/doc/pub/week44/html/._week44-bs055.html
+++ b/doc/pub/week44/html/._week44-bs055.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,21 +397,62 @@ MathJax.Hub.Config({
-
Disadvantages
+
Visualizing Trees, More examples
+
+
+
-
- Unfortunately, trees generally do not have the same level of predictive accuracy as some of the other regression and classification approaches
- If continuous features are used the tree may become quite large and hence less interpretable
- Decision trees are prone to overfit the training data and hence do not well generalize the data if no stopping criteria or improvements like pruning, boosting or bagging are implemented
- Small changes in the data may lead to a completely different tree. This issue can be addressed by using ensemble methods like bagging, boosting or random forests
- Unbalanced datasets where some target feature values occur much more frequently than others may lead to biased trees since the frequently occurring feature values are preferred over the less frequently occurring ones.
- If the number of features is relatively large (high dimensional) and the number of instances is relatively low, the tree might overfit the data
- Features with many levels may be preferred over features with less levels since for them it is more easy to split the dataset such that the sub datasets only contain pure target feature values. This issue can be addressed by preferring for instance the information gain ratio as splitting criteria over information gain
-
-
However, by aggregating many decision trees, using methods like
-bagging, random forests, and boosting, the predictive performance of
-trees can be substantially improved.
-
@@ -369,6 +478,8 @@ trees can be substantially improved.
63
64
65
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs056.html b/doc/pub/week44/html/._week44-bs056.html
index 25db2326b..fc4b19fd4 100644
--- a/doc/pub/week44/html/._week44-bs056.html
+++ b/doc/pub/week44/html/._week44-bs056.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,28 +397,53 @@ MathJax.Hub.Config({
-
Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+
Visualizing the Tree, The Moons
-
As stated above and seen in many of the examples discussed here about
-a single decision tree, we often end up overfitting our training
-data. This normally means that we have a high variance. Can we reduce
-the variance of a statistical learning method?
-
+
+
-
- Voting classifiers
- Bagging and Pasting
- Random forests
- Boosting methods, from adaptive to Extreme Gradient Boosting (XGBoost)
-
-
We discuss these methods here.
@@ -375,6 +468,9 @@ try to explain here. These are
63
64
65
+
66
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs057.html b/doc/pub/week44/html/._week44-bs057.html
index 2e4f04814..f33366092 100644
--- a/doc/pub/week44/html/._week44-bs057.html
+++ b/doc/pub/week44/html/._week44-bs057.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,13 +397,39 @@ MathJax.Hub.Config({
-
An Overview of Ensemble Methods
+
Other ways of visualizing the trees
+
+
Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.
+
+
+
+
-
-
-
-
-
@@ -359,6 +453,10 @@ MathJax.Hub.Config({
63
64
65
+
66
+
67
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs058.html b/doc/pub/week44/html/._week44-bs058.html
index 8ade5ec96..0297a0faa 100644
--- a/doc/pub/week44/html/._week44-bs058.html
+++ b/doc/pub/week44/html/._week44-bs058.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,21 +397,42 @@ MathJax.Hub.Config({
-
Bagging
+
Printing out as text
-
The plain decision trees suffer from high
-variance. This means that if we split the training data into two parts
-at random, and fit a decision tree to both halves, the results that we
-get could be quite different. In contrast, a procedure with low
-variance will yield similar results if applied repeatedly to distinct
-data sets; linear regression tends to have low variance, if the ratio
-of \( n \) to \( p \) is moderately large.
+
Alternatively, the tree can also be exported in textual format with the function exporttext.
+This method doesn’t require the installation of external libraries and is more compact:
-
Bootstrap aggregation , or just bagging , is a
-general-purpose procedure for reducing the variance of a statistical
-learning method.
-
+
+
+
+
@@ -366,6 +455,11 @@ learning method.
63
64
65
+
66
+
67
+
68
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs059.html b/doc/pub/week44/html/._week44-bs059.html
index d031ebfd3..3f5e1723d 100644
--- a/doc/pub/week44/html/._week44-bs059.html
+++ b/doc/pub/week44/html/._week44-bs059.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,30 +397,17 @@ MathJax.Hub.Config({
-
More bagging
+
Algorithms for Setting up Decision Trees
-
Bagging typically results in improved accuracy
-over prediction using a single tree. Unfortunately, however, it can be
-difficult to interpret the resulting model. Recall that one of the
-advantages of decision trees is the attractive and easily interpreted
-diagram that results.
-
-
-
However, when we bag a large number of trees, it is no longer
-possible to represent the resulting statistical learning procedure
-using a single tree, and it is no longer clear which variables are
-most important to the procedure. Thus, bagging improves prediction
-accuracy at the expense of interpretability. Although the collection
-of bagged trees is much more difficult to interpret than a single
-tree, one can obtain an overall summary of the importance of each
-predictor using the MSE (for bagging regression trees) or the Gini
-index (for bagging classification trees). In the case of bagging
-regression trees, we can record the total amount that the MSE is
-decreased due to splits over a given predictor, averaged over all \( B \) possible
-trees. A large value indicates an important predictor. Similarly, in
-the context of bagging classification trees, we can add up the total
-amount that the Gini index is decreased by splits over a given
-predictor, averaged over all \( B \) trees.
+
Two algorithms stand out in the set up of decision trees:
+
+ The CART (Classification And Regression Tree) algorithm for both classification and regression
+ The ID3 algorithm based on the computation of the information gain for classification
+
+
We discuss both algorithms with applications here. The popular library
+Scikit-Learn uses the CART algorithm. For classification problems
+you can use either the gini index or the entropy to split a tree
+in two branches.
@@ -375,6 +430,12 @@ predictor, averaged over all \( B \) trees.
63
64
65
+
66
+
67
+
68
+
69
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs060.html b/doc/pub/week44/html/._week44-bs060.html
index 8682cebf1..d81d6f94c 100644
--- a/doc/pub/week44/html/._week44-bs060.html
+++ b/doc/pub/week44/html/._week44-bs060.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,42 +397,30 @@ MathJax.Hub.Config({
-
Simple Voting Example, head or tail
+
The CART algorithm for Classification
-
-
+
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
+This could be for example a threshold set by a number below a certain circumference of a malign tumor.
+
+
How do we find these two quantities?
+We search for the pair \( (k,t_k) \) that produces the purest subset using for example the gini factor \( G \).
+The cost function it tries to minimize is then
+
+$$
+C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}},
+$$
+
+
where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \)
+ is the number of instances in the left/right subset
+
+
+
Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets
+and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the
+\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other
+hyperparameters control additional stopping conditions such as the \( min\_samples\_split \),
+\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).
+
@@ -385,6 +441,13 @@ plt. show()
63
64
65
+
66
+
67
+
68
+
69
+
70
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs061.html b/doc/pub/week44/html/._week44-bs061.html
index d9dff40cd..b849267d5 100644
--- a/doc/pub/week44/html/._week44-bs061.html
+++ b/doc/pub/week44/html/._week44-bs061.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,72 +397,30 @@ MathJax.Hub.Config({
-
Using the Voting Classifier
+
The CART algorithm for Regression
-
-
+
the mean value of all observations in a specific node.
+
Without any regularization, the regression task for decision trees,
+just like for classification tasks, is prone to overfitting.
+
@@ -414,6 +440,14 @@ voting_clf. fit(X_train, y_train)
63
64
65
+
66
+
67
+
68
+
69
+
70
+
71
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs062.html b/doc/pub/week44/html/._week44-bs062.html
index ad3a77415..b07a22d25 100644
--- a/doc/pub/week44/html/._week44-bs062.html
+++ b/doc/pub/week44/html/._week44-bs062.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,125 +397,46 @@ MathJax.Hub.Config({
-
Please, not the moons again! Voting and Bagging
+
Computing the Gini index
+
The example we will look at is a classical one in many Machine
+Learning applications. Based on various meteorological features, we
+have several so-called attributes which decide whether we at the end
+will do some outdoor activity like skiing, going for a bike ride etc
+etc. The table here contains the feautures outlook , temperature ,
+humidity and wind . The target or output is whether we ride
+(True=1) or whether we do something else that day (False=0). The
+attributes for each feature are then sunny, overcast and rain for the
+outlook, hot, cold and mild for temperature, high and normal for
+humidity and weak and strong for wind.
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
The table here summarizes the various attributes and
+
+
+
+
+Day Outlook Temperature Humidity Wind Ride
+
+
+ 1 Sunny Hot High Weak 0
+ 2 Sunny Hot High Strong 1
+ 3 Overcast Hot High Weak 1
+ 4 Rain Mild High Weak 1
+ 5 Rain Cool Normal Weak 1
+ 6 Rain Cool Normal Strong 0
+ 7 Overcast Cool Normal Strong 1
+ 8 Sunny Mild High Weak 0
+ 9 Sunny Cool Normal Weak 1
+ 10 Rain Mild Normal Weak 1
+ 11 Sunny Mild Normal Strong 1
+ 12 Overcast Mild High Strong 1
+ 13 Overcast Hot Normal Weak 1
+ 14 Rain Mild High Strong 0
+
+
+
+
@@ -466,6 +455,15 @@ voting_clf. fit(X_train, y_train)
63
64
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
...
+
81
»
diff --git a/doc/pub/week44/html/._week44-bs063.html b/doc/pub/week44/html/._week44-bs063.html
index b9aa8ce8b..b4b1b6cc5 100644
--- a/doc/pub/week44/html/._week44-bs063.html
+++ b/doc/pub/week44/html/._week44-bs063.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -329,7 +397,7 @@ MathJax.Hub.Config({
-
Bagging Examples
+
@@ -338,104 +406,73 @@ MathJax.Hub.Config({
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -468,6 +505,16 @@ plt
. show()
63
64
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
...
+
81
»
diff --git a/doc/pub/week44/html/week44-bs.html b/doc/pub/week44/html/week44-bs.html
index 2075e6cdc..6872062e3 100644
--- a/doc/pub/week44/html/week44-bs.html
+++ b/doc/pub/week44/html/week44-bs.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -42,50 +42,6 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -219,7 +175,103 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -247,7 +299,7 @@ MathJax.Hub.Config({
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -257,67 +309,83 @@ MathJax.Hub.Config({
Overview of week 44
Digression First
A short Discussion of Project 2
- Learning Rate and more
- Thursday, Principal Component Analysis
- A kind of Bird's view on PCA
- Thursday: Clustering and Unsupervised Learning
- Basic Idea of the \( k \)-means Clustering Algorithm
- The \( k \)-means Algorithm
- Basic Math of the \( k \)-means Algorithm
- Within Cluster Point Scatter
- More Details
- Total Cluster Variance
- The \( k \)-means Clustering Algorithm
- Summarizing
- Writing our own Code, the Data Set
- Implementing the \( k \)-means Algorithm
- Plotting
- Continuing
- Wrapping it up
- Decision trees, overarching aims
- Basics of a tree
- A Sketch of a Tree, Regression problem
- A Sketch of a Tree, Classification problem
- A typical Decision Tree with its pertinent Jargon, Classification Problem
- General Features
- How do we set it up?
- Decision trees and Regression
- Building a tree, regression
- A top-down approach, recursive binary splitting
- Making a tree
- Pruning the tree
- Cost complexity pruning
- Schematic Regression Procedure
- A Classification Tree
- Growing a classification tree
- Classification tree, how to split nodes
- Visualizing the Tree, Classification
- Visualizing the Tree, The Moons
- Other ways of visualizing the trees
- Printing out as text
- Algorithms for Setting up Decision Trees
- The CART algorithm for Classification
- The CART algorithm for Regression
- Computing the Gini index
- Simple Python Code to read in Data and perform Classification
- Computing the Gini Factor
- Entropy and the ID3 algorithm
- Cancer Data again now with Decision Trees and other Methods
- Another example, the moons again
- Playing around with regions
- Regression trees
- Final regressor code
- Pros and cons of trees, pros
- Disadvantages
- Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
- An Overview of Ensemble Methods
- Bagging
- More bagging
- Simple Voting Example, head or tail
- Using the Voting Classifier
- Please, not the moons again! Voting and Bagging
- Bagging Examples
- Making your own Bootstrap: Changing the Level of the Decision Tree
+ Decision trees, overarching aims
+ Basics of a tree
+ A Sketch of a Tree, Regression problem
+ A Sketch of a Tree, Classification problem
+ A typical Decision Tree with its pertinent Jargon, Classification Problem
+ General Features
+ How do we set it up?
+ Decision trees and Regression
+ Building a tree, regression
+ A top-down approach, recursive binary splitting
+ Making a tree
+ Pruning the tree
+ Cost complexity pruning
+ Schematic Regression Procedure
+ A Classification Tree
+ Growing a classification tree
+ Classification tree, how to split nodes
+ Visualizing the Tree, Classification
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Pros and cons of trees, pros
+ Disadvantages
+ Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
+ An Overview of Ensemble Methods
+ Bagging
+ More bagging
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Please, not the moons again! Voting and Bagging
+ Bagging Examples
+ Making your own Bootstrap: Changing the Level of the Decision Tree
+ Why binary splits?
+ Computing a Tree using the Gini Index
+ The Table
+ Computing the various Gini Indices
+ Computing the various Gini Indices, Hours slept
+ Computing the various Gini Indices, Hours studied
+ A possible code using Scikit-Learn
+ Visualizing Trees, More examples
+ Visualizing the Tree, The Moons
+ Other ways of visualizing the trees
+ Printing out as text
+ Algorithms for Setting up Decision Trees
+ The CART algorithm for Classification
+ The CART algorithm for Regression
+ Computing the Gini index
+ Simple Python Code to read in Data and perform Classification
+ Computing the Gini Factor
+ Entropy and the ID3 algorithm
+ Cancer Data again now with Decision Trees and other Methods
+ Another example, the moons again
+ Playing around with regions
+ Regression trees
+ Final regressor code
+ Why Voting?
+ Tossing coins
+ Standard imports first
+ Simple Voting Example, head or tail
+ Using the Voting Classifier
+ Voting and Bagging
+ Random forests
+ Random Forest Algorithm
+ Random Forests Compared with other Methods on the Cancer Data
+ Compare Bagging on Trees with Random Forests
@@ -331,7 +399,7 @@ MathJax.Hub.Config({
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -347,7 +415,7 @@ MathJax.Hub.Config({
-Aug 23, 2022
+Oct 30, 2022
@@ -372,7 +440,7 @@ MathJax.Hub.Config({
9
10
...
-
65
+
81
»
diff --git a/doc/pub/week44/html/week44-reveal.html b/doc/pub/week44/html/week44-reveal.html
index 577cf32fa..6261ee517 100644
--- a/doc/pub/week44/html/week44-reveal.html
+++ b/doc/pub/week44/html/week44-reveal.html
@@ -9,8 +9,8 @@ doconce format html week44-reveal.html week44-reveal reveal --html_slide_theme=b
-
-
Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+
Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -168,7 +168,7 @@ MathJax.Hub.Config({
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -184,7 +184,7 @@ MathJax.Hub.Config({
-Aug 23, 2022
+Oct 30, 2022
@@ -198,8 +198,8 @@ MathJax.Hub.Config({
Overview of week 44
-
Thursday: Wrapping up PCA from last week, Clustering and basics of decision trees, classification and regression algorithms
-
Friday: Decision trees, voting models and bagging
+
Thursday: Basics of decision trees, classification and regression algorithms
+
Friday: Decision trees and ensemble models (bagging and random forests)
@@ -218,7 +216,6 @@ MathJax.Hub.Config({
Decision Trees: Geron's chapter 6 covers decision trees while ensemble models, voting and bagging are discussed in chapter 7. See also lecture from STK-IN4300, lecture 7 . Chapter 9.2 of Hastie et al contains also a good discussion.
-
Clustering and PCA, see Geron's chapter 8 and Lecture notes . Bishop's chapter 9.1 is also a good read.
@@ -369,670 +366,6 @@ plt.show()
-
-Learning Rate and more
-
-When developing your own gradient descent code, it is useful to test
-it first on a standard ordinary least squares problem. Then the
-Hessian matrix is determined by the design matrix only, namely
-\( \boldsymbol{H}\propto \boldsymbol{X}^T\boldsymbol{X} \).
-
-
-The optimal learning rate is determined by the inverse of the largest
-eigenvalue of \( \boldsymbol{H} \). This can be used as a guideline for the
-learning rate guess.
-
-
-Keeping this fixed, can aid in studyng the dependence on say the mean
-square value for OLS as function of the number of batches and epochs
-in your stochastic gradient descent code. See for example the code
-examples for week 40 (right before the neural network material).
-
-
-
-
-Thursday, Principal Component Analysis
-
-For the principal component analysis,
-see slides from week 43 , in particular from slide 28 and forward
-
-
-
-
-A kind of Bird's view on PCA
-
-Why do we maximize variance during Principal Component Analysis?
-
-Variance is a measure of the variability of the data you
-have. Potentially the number of components is infinite, so you want to "squeeze" the most
-information in each component of the finite set you build.
-
-
-If, to exaggerate, you were to select a single principal component,
-you would want it to account for the most variability possible: hence
-the search for maximum variance, so that the one component collects
-the most "uniqueness" from the data set.
-
-
-Maximizing the component vector variances is the same as maximizing
-the 'uniqueness' of those vectors. The vectors are as distant
-from each other as possible (orthogonal to each other).
-
-
-Take for example a situation where you have 2 lines that are
-orthogonal in a 3D space. You can capture the environment much more
-completely with those orthogonal lines than 2 lines that are parallel
-(or nearly parallel). When applied to very high dimensional states
-using very few vectors, this becomes a much more important
-relationship among the vectors to maintain. In a linear algebra sense
-you want independent rows to be produced by PCA, otherwise some of
-those rows will be redundant.
-
-
-
-
-Thursday: Clustering and Unsupervised Learning
-
-In general terms cluster analysis, or clustering, is the task of grouping a
-data-set into different distinct categories based on some measure of equality of
-the data. This measure is often referred to as a metric or similarity
-measure in the literature (note: sometimes we deal with a dissimilarity
-measure instead). Usually, these metrics are formulated as some kind of
-distance function between points in a high-dimensional space.
-
-
-The simplest, and also the most
-common is the Euclidean distance .
-
-
-
-
-Basic Idea of the \( k \)-means Clustering Algorithm
-
-The simplest of all clustering algorithms is the k-means algorithm
-, sometimes also referred to as Lloyds algorithm . It is the simplest and also
-the most common. From its simplicity it obtains both strengths and weaknesses.
-These will be discussed in more detail later. The \( k \)-means algorithm is a
-centroid based clustering algorithm.
-
-
-
-
-The \( k \)-means Algorithm
-
-Assume, we are given \( n \) data points and we wish to split the data into \( K < n \)
-different categories, or clusters. We label each cluster by an integer
-
-
-
-$$ k\in\{1, \cdots, K \}.
-$$
-
-
-
In the basic k-means algorithm each point is assigned to only
-one cluster \( k \), and these assignments are non-injective i.e. many-to-one. We
-can think of these mappings as an encoder \( k = C(i) \), which assigns the \( i \)-th
-data-point \( \bf x_i \) to the \( k \)-th cluster.
-
-
-\( k \)-means algorithm in words:
-
-
We start with guesses / random initializations of our \( k \) cluster centers/centroids
-
For each centroid the points that are most similar are identified
-
Then we move / replace each centroid with a coordinate average of all the points that were assigned to that centroid.
-
Iterate 2-3 until the centroids no longer move (to some tolerance)
-
-
-
-
-Basic Math of the \( k \)-means Algorithm
-
-We assume we have \( n \) data-points
-
-$$
-\begin{equation}\tag{1}
- \boldsymbol{x_i} = \{x_{i, 1}, \cdots, x_{i, p}\}\in\mathbb{R}^p.
-\end{equation}
-$$
-
-
-
which we wish to group into \( K < n \) clusters. For our dissimilarity measure we
-use the squared Euclidean distance
-
-
-$$
-\begin{equation}\tag{2}
- d(\boldsymbol{x_i}, \boldsymbol{x_i'}) = \sum_{j=1}^p(x_{ij} - x_{i'j})^2
- = ||\boldsymbol{x_i} - \boldsymbol{x_{i'}}||^2
-\end{equation}
-$$
-
-
-
-
-Within Cluster Point Scatter
-
-We define the so called within-cluster point scatter which gives us a
-measure of how close each data point assigned to the same cluster tends to be to
-the all the others.
-
-
-$$
-\begin{equation}\tag{3}
- W(C) = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k}
- \sum_{C(i')=k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) =
- \sum_{k=1}^KN_k\sum_{C(i)=k}||\boldsymbol{x_i} - \boldsymbol{\overline{x_k}}||^2
-\end{equation}
-$$
-
-
-
where \( \boldsymbol{\overline{x_k}} \) is the mean vector associated with the \( k \)-th
-cluster, and \( N_k = \sum_{i=1}^nI(C(i) = k) \), where the \( I() \) notation is
-similar to the Kronecker delta (Commonly used in statistics, it just means that
-when \( i = k \) we have the encoder \( C(i) \) ). In other words, the within-cluster
-scatter measures the compactness of each cluster with respect to the data points
-assigned to each cluster. This is the quantity that the \( k \)-means algorithm aims
-to minimize. We refer to this quantity \( W(C) \) as the within cluster scatter
-because of its relation to the total scatter .
-
-
-
-
-More Details
-
-We have
-
-$$
-\begin{equation}\tag{4}
- T = W(C) + B(C) = \frac{1}{2}\sum_{i=1}^n
- \sum_{i'=1}^nd(\boldsymbol{x_i}, \boldsymbol{x_{i'}})
- = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k}
- \Big(\sum_{C(i') = k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})
- + \sum_{C(i')\neq k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})\Big).
-\end{equation}
-$$
-
-
-
This is a quantity that is conserved throughout the \( k \)-means algorithm. It can
-be thought of as the total amount of information in the data, and it is composed
-of the aforementioned within-cluster scatter and the between-cluster scatter
-\( B(C) \). In methods such as principle component analysis the total scatter is not
-conserved.
-
-
-
-
-Total Cluster Variance
-Given a cluster mean \( \boldsymbol{m_k} \) we define the total cluster variance
-
-$$
-\begin{equation}\tag{5}
- \min_{C, \{\boldsymbol{m_k}\}_1^K}\sum_{k=1}^KN_k\sum||\boldsymbol{x_i} - \boldsymbol{m_k}||^2
-\end{equation}
-$$
-
-
-
Now we have all the pieces necessary to formally revisit the \( k \)-means algorithm.
-
-
-
-The \( k \)-means Clustering Algorithm
-
-The \( k \)-means clustering algorithm goes as follows
-
-
-
For a given cluster assignment \( C \), and \( k \) cluster means \( \left\{m_1, \cdots, m_k\right\} \). We minimize the total cluster variance with respect to the cluster means \( \{m_k\} \) yielding the means of the currently assigned clusters.
-
Given a current set of \( k \) means \( \{m_k\} \) the total cluster variance is minimized by assigning each observation to the closest (current) cluster mean. That is
-$$C(i) = \underset{1\leq k\leq K}{\mathrm{argmin}} ||\boldsymbol{x_i} - \boldsymbol{m_k}||^2$$
-
-
Steps 1 and 2 are repeated until the assignments do not change.
-
-
-
-
-Summarizing
-
-
-
Before we start we specify a number \( k \) which is the number of clusters we want to try to separate our data into.
-
We initially choose \( k \) random data points in our data as our initial centroids, or means (this is where the name comes from).
-
Assign each data point to their closest centroid, based on the squared Euclidean distance.
-
For each of the \( k \) cluster we update the centroid by calculating new mean values for all the data points in the cluster.
-
Iteratively minimize the within cluster scatter by performing steps (3, 4) until the new assignments stop changing (can be to some tolerance) or until a maximum number of iterations have passed.
-
-
-
-
-Writing our own Code, the Data Set
-
-Let us now program the most basic version of the algorithm using nothing but
-Python with numpy arrays. This code is kept intentionally simple to gradually
-progress our understanding. There is no vectorization of any kind, and even most
-helper functions are not utilized.
-
-
-We need first a dataset to do our cluster analysis on. In our case
-this is a plain vanilla data set using random numbers using a
-Gaussian distribution.
-
-
-
-
-
-
-Next we define functions, for ease of use later, to generate Gaussians and to
-set up our toy data set.
-
-
-
-
-
-
-
-Implementing the \( k \)-means Algorithm
-
-With the above dataset we start
-implementing the \( k \)-means algorithm.
-
-
-
-
-
-
-
-
-Plotting
-
-
-
-
-So what do we have so far? We have 'picked' \( k \) centroids at random from our
-data points. There are other ways of more intelligently choosing their
-initializations, however for our purposes randomly is fine. Then we have
-initialized an array 'distances' which holds the information of the distance,
-or dissimilarity , of every point to of our centroids. Finally, we have
-initialized an array 'cluster_labels' which according to our distances array
-holds the information of to which centroid every point is assigned. This was the
-first pass of our algorithm. Essentially, all we need to do now is repeat the
-distance and assignment steps above until we have reached a desired convergence
-or a maximum amount of iterations.
-
-
-
-
-
-
-Wrapping it up
-We now have a simple , un-optimized \( k \)-means
-clustering implementation. Lets plot the final result
-
-
-
-
-
-
-
-
-
-
-
Decision trees, overarching aims
@@ -2962,6 +2295,1648 @@ plt.show()
+
+Why binary splits?
+
+It is custom to split to a tree uising binary splits. The reason is
+that multiway splits fragment the data too quickly, leaving
+insufficient data at the next level down. Multiway splits can be
+achieved by a series of binary split and this is normally preferred.
+
+
+
+
+Computing a Tree using the Gini Index
+
+Consider the following example with attributes/features and two
+possible outcomes (classes) for each attribute. Assume we wish to find some
+correlations between the average grade of a student as function of the
+number of hours studied and hours slept. We want also to correlate the
+grade in a given course with the general trend, whether the students
+recently has gotten grades below average or above.
+
+
+We have three features/attributes
+
+
Trend of average grades before present course, classified as either below or above the average grade of the whole class
+
+
The number of hours studies, classified again as either higher (more than 3 hours per day) or lower . Here we have used a standard for one \( ECTS \) which is scaled to 25-30 hours of work for a semester which lasts 18 weeks, with 15 weeks of lectures and 3 weeks for exams, assuming a total of 30 ECTS per semester.
+
The number of hours slept as high for more than \( 8 \) hours and below for less than 8 hours of sleep, classified again as either high or low
+
The final grade whether it is above or below average
+
+
+
+
+The Table
+
+
+
+Grade Trend Hours slept Hours Studied Grade
+
+
+ Above Low High Above
+ Below High Low Below
+ Above Low High Above
+ Above High High Above
+ Below Low High Below
+ Above Low Low Below
+ Below High High Below
+ Below Low High Below
+ Above Low Low Below
+ Above High High Above
+
+
+
+
+
+Computing the various Gini Indices
+
+In computations we will translate all classes into numbers. Being
+these binary classes, they can easily be split into ones and zeros.
+
+
+
+
Gini index for Average trend
+
+
See handwritten notes for Thursday November 11
+
+
+
+
+Computing the various Gini Indices, Hours slept
+
+
+
Gini index for hour slept
+
+
See handwritten notes for Thursday November 11
+
+
+
+
+Computing the various Gini Indices, Hours studied
+
+
+
Gini index for hour studied
+
+
See handwritten notes for Thursday November 11
+
+
+For final tree, see the above handwritten notes
+
+
+
+A possible code using Scikit-Learn
+
+
+
+
+
+
+
+Visualizing Trees, More examples
+
+
+
+
+
+
+Visualizing the Tree, The Moons
+
+
+
+
+
+
+Other ways of visualizing the trees
+
+Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.
+
+
+
+
+
+
+
+Printing out as text
+
+Alternatively, the tree can also be exported in textual format with the function exporttext.
+This method doesn’t require the installation of external libraries and is more compact:
+
+
+
+
+
+
+
+
+Algorithms for Setting up Decision Trees
+
+Two algorithms stand out in the set up of decision trees:
+
+
The CART (Classification And Regression Tree) algorithm for both classification and regression
+
The ID3 algorithm based on the computation of the information gain for classification
+
+
+
We discuss both algorithms with applications here. The popular library
+Scikit-Learn uses the CART algorithm. For classification problems
+you can use either the gini index or the entropy to split a tree
+in two branches.
+
+
+
+
+The CART algorithm for Classification
+
+For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
+This could be for example a threshold set by a number below a certain circumference of a malign tumor.
+
+
+How do we find these two quantities?
+We search for the pair \( (k,t_k) \) that produces the purest subset using for example the gini factor \( G \).
+The cost function it tries to minimize is then
+
+
+$$
+C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}},
+$$
+
+
+
where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \)
+ is the number of instances in the left/right subset
+
+
+Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets
+and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the
+\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other
+hyperparameters control additional stopping conditions such as the \( min\_samples\_split \),
+\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).
+
+
+
+
+The CART algorithm for Regression
+
+The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
+training set in a way that minimizes say the gini or entropy impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now
+
+
+$$
+C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}.
+$$
+
+
+
Here the MSE for a specific node is defined as
+
+$$
+\mathrm{MSE}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}(\overline{y}_{\mathrm{node}}-y_i)^2,
+$$
+
+
+
with
+
+$$
+\overline{y}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}y_i,
+$$
+
+
+
the mean value of all observations in a specific node.
+
+Without any regularization, the regression task for decision trees,
+just like for classification tasks, is prone to overfitting.
+
+
+
+
+Computing the Gini index
+
+The example we will look at is a classical one in many Machine
+Learning applications. Based on various meteorological features, we
+have several so-called attributes which decide whether we at the end
+will do some outdoor activity like skiing, going for a bike ride etc
+etc. The table here contains the feautures outlook , temperature ,
+humidity and wind . The target or output is whether we ride
+(True=1) or whether we do something else that day (False=0). The
+attributes for each feature are then sunny, overcast and rain for the
+outlook, hot, cold and mild for temperature, high and normal for
+humidity and weak and strong for wind.
+
+
+The table here summarizes the various attributes and
+
+
+Day Outlook Temperature Humidity Wind Ride
+
+
+ 1 Sunny Hot High Weak 0
+ 2 Sunny Hot High Strong 1
+ 3 Overcast Hot High Weak 1
+ 4 Rain Mild High Weak 1
+ 5 Rain Cool Normal Weak 1
+ 6 Rain Cool Normal Strong 0
+ 7 Overcast Cool Normal Strong 1
+ 8 Sunny Mild High Weak 0
+ 9 Sunny Cool Normal Weak 1
+ 10 Rain Mild Normal Weak 1
+ 11 Sunny Mild Normal Strong 1
+ 12 Overcast Mild High Strong 1
+ 13 Overcast Hot Normal Weak 1
+ 14 Rain Mild High Strong 0
+
+
+
+
+
+
+
+Computing the Gini Factor
+
+The above functions (gini, entropy and misclassification error) are
+important components of the so-called CART algorithm. We will discuss
+this algorithm below after we have discussed the information gain
+algorithm ID3.
+
+
+In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.
+
+
+
+
+
+
+
+Entropy and the ID3 algorithm
+
+The ID3 algorithm learns decision trees by constructing
+them in a top down way, beginning with the question which attribute should be tested at the root of the tree ?
+
+
+
+
Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.
+
The best attribute is selected and used as the test at the root node of the tree.
+
A descendant of the root node is then created for each possible value of this attribute.
+
Training examples are sorted to the appropriate descendant node.
+
The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.
+
This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.
+
+
+
The ID3 algorithm selects which attribute to test at each node in the
+tree.
+
+
+We would like to select the attribute that is most useful for classifying
+examples.
+
+
+What is a good quantitative measure of the worth of an attribute?
+
+Information gain measures how well a given attribute separates the
+training examples according to their target classification.
+
+
+The ID3 algorithm uses this information gain measure to select among the candidate
+attributes at each step while growing the tree.
+
+
+
+
+Cancer Data again now with Decision Trees and other Methods
+
+
+
+
+
+
+Another example, the moons again
+
+
+
+
+
+
+Playing around with regions
+
+
+
+
+
+
+Regression trees
+
+
+
+
+
+
+
+
+
+
+Final regressor code
+
+
+
+
+
+
+
+
+
+
+Why Voting?
+
+The idea behind boosting, and voting as well can be phrased as follows:
+Can a group of people somehow arrive at highly
+reasoned decisions, despite the weak judgement of the individual
+members?
+
+
+The aim is to create a good classifier by combining several weak classifiers.
+A weak classifier is a classifier which is able to produce results that are only slightly better than guessing at random.
+
+
+The basic approach is to apply repeatedly (in boosting this is done in an iterative way) a weak classifier to modifications of the data.
+In voting we simply apply the law of large numbers while in boosting we give more weight to misclassified data in
+each iteration.
+
+
+Decision trees play an important role as our weak classifier. They serve as the basic method.
+
+
+
+Tossing coins
+
+The simplest case is a so-called voting ensemble. To illustrate this,
+think of yourself tossing coins with a biased outcome of 51 per cent
+for heads and 49% for tails. With only few tosses,
+you may not clearly see this distribution for heads and tails. However, after some
+thousands of tosses, there will be a clear majority of heads. With 2000 tosses
+you should see approximately 1020 heads and 980 tails.
+
+
+We can then state that the outcome is a clear majority of heads. If
+you do this ten thousand times, it is easy to see that there is a 97%
+likelihood of a majority of heads.
+
+
+Another example would be to collect all polls before an
+election. Different polls may show different likelihoods for a
+candidate winning with say a majority of the popular vote. The majority vote
+would then consist in many polls indicating that this candidate will
+actually win.
+
+
+The example here shows how we can implement the coin tossing case,
+clealry demostrating that after some tosses we see the law of large
+numbers kicking in.
+
+
+
+
+Standard imports first
+
+
+
+
+
+
+
+Simple Voting Example, head or tail
+
+
+
+
+
+
+Using the Voting Classifier
+
+We can use the voting classifier on other data sets, here the exciting binary case of two distinct objects using the make moons functionality of Scikit-Learn .
+
+
+
+
+
+
+Voting and Bagging
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Random forests
+
+Random forests provide an improvement over bagged trees by way of a
+small tweak that decorrelates the trees.
+
+
+As in bagging, we build a
+number of decision trees on bootstrapped training samples. But when
+building these decision trees, each time a split in a tree is
+considered, a random sample of \( m \) predictors is chosen as split
+candidates from the full set of \( p \) predictors. The split is allowed to
+use only one of those \( m \) predictors.
+
+
+A fresh sample of \( m \) predictors is
+taken at each split, and typically we choose
+
+
+
+$$
+m\approx \sqrt{p}.
+$$
+
+
+
In building a random forest, at
+each split in the tree, the algorithm is not even allowed to consider
+a majority of the available predictors.
+
+
+The reason for this is rather clever. Suppose that there is one very
+strong predictor in the data set, along with a number of other
+moderately strong predictors. Then in the collection of bagged
+variable importance random forest trees, most or all of the trees will
+use this strong predictor in the top split. Consequently, all of the
+bagged trees will look quite similar to each other. Hence the
+predictions from the bagged trees will be highly correlated.
+Unfortunately, averaging many highly correlated quantities does not
+lead to as large of a reduction in variance as averaging many
+uncorrelated quantities. In particular, this means that bagging will
+not lead to a substantial reduction in variance over a single tree in
+this setting.
+
+
+
+
+Random Forest Algorithm
+The algorithm described here can be applied to both classification and regression problems.
+
+We will grow of forest of say \( B \) trees.
+
+
For \( b=1:B \)
+
+
+
Draw a bootstrap sample from the training data organized in our \( \boldsymbol{X} \) matrix.
+
+
We grow then a random forest tree \( T_b \) based on the bootstrapped data by repeating the steps outlined till we reach the maximum node size is reached
+
+
+
we select \( m \le p \) variables at random from the \( p \) predictors/features
+
+
pick the best split point among the \( m \) features using for example the CART algorithm and create a new node
+
+
split the node into daughter nodes
+
+
+
+
+
Output then the ensemble of trees \( \{T_b\}_1^{B} \) and make predictions for either a regression type of problem or a classification type of problem.
+
+
+
+
+Random Forests Compared with other Methods on the Cancer Data
+
+
+
+
+Recall that the cumulative gains curve shows the percentage of the
+overall number of cases in a given category gained by targeting a
+percentage of the total number of cases.
+
+
+Similarly, the receiver operating characteristic curve, or ROC curve,
+displays the diagnostic ability of a binary classifier system as its
+discrimination threshold is varied. It plots the true positive rate against the false positive rate.
+
+
+
+
+Compare Bagging on Trees with Random Forests
+
+
+
diff --git a/doc/pub/week44/html/week44-solarized.html b/doc/pub/week44/html/week44-solarized.html
index 341a689a2..4b522b2d0 100644
--- a/doc/pub/week44/html/week44-solarized.html
+++ b/doc/pub/week44/html/week44-solarized.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --pygments_html_style=perldoc --html_style=sol
-
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -69,50 +69,6 @@ div.toc p,a {
2,
None,
'a-short-discussion-of-project-2'),
- ('Learning Rate and more', 2, None, 'learning-rate-and-more'),
- ('Thursday, Principal Component Analysis',
- 2,
- None,
- 'thursday-principal-component-analysis'),
- ("A kind of Bird's view on PCA",
- 2,
- None,
- 'a-kind-of-bird-s-view-on-pca'),
- ('Thursday: Clustering and Unsupervised Learning',
- 2,
- None,
- 'thursday-clustering-and-unsupervised-learning'),
- ('Basic Idea of the $k$-means Clustering Algorithm',
- 2,
- None,
- 'basic-idea-of-the-k-means-clustering-algorithm'),
- ('The $k$-means Algorithm', 2, None, 'the-k-means-algorithm'),
- ('Basic Math of the $k$-means Algorithm',
- 2,
- None,
- 'basic-math-of-the-k-means-algorithm'),
- ('Within Cluster Point Scatter',
- 2,
- None,
- 'within-cluster-point-scatter'),
- ('More Details', 2, None, 'more-details'),
- ('Total Cluster Variance', 2, None, 'total-cluster-variance'),
- ('The $k$-means Clustering Algorithm',
- 2,
- None,
- 'the-k-means-clustering-algorithm'),
- ('Summarizing', 2, None, 'summarizing'),
- ('Writing our own Code, the Data Set',
- 2,
- None,
- 'writing-our-own-code-the-data-set'),
- ('Implementing the $k$-means Algorithm',
- 2,
- None,
- 'implementing-the-k-means-algorithm'),
- ('Plotting', 2, None, 'plotting'),
- ('Continuing', 2, None, 'continuing'),
- ('Wrapping it up', 2, None, 'wrapping-it-up'),
('Decision trees, overarching aims',
2,
None,
@@ -246,7 +202,103 @@ div.toc p,a {
'Tree',
2,
None,
- 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree')]}
+ 'making-your-own-bootstrap-changing-the-level-of-the-decision-tree'),
+ ('Why binary splits?', 2, None, 'why-binary-splits'),
+ ('Computing a Tree using the Gini Index',
+ 2,
+ None,
+ 'computing-a-tree-using-the-gini-index'),
+ ('The Table', 2, None, 'the-table'),
+ ('Computing the various Gini Indices',
+ 2,
+ None,
+ 'computing-the-various-gini-indices'),
+ ('Computing the various Gini Indices, Hours slept',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-slept'),
+ ('Computing the various Gini Indices, Hours studied',
+ 2,
+ None,
+ 'computing-the-various-gini-indices-hours-studied'),
+ ('A possible code using Scikit-Learn',
+ 2,
+ None,
+ 'a-possible-code-using-scikit-learn'),
+ ('Visualizing Trees, More examples',
+ 2,
+ None,
+ 'visualizing-trees-more-examples'),
+ ('Visualizing the Tree, The Moons',
+ 2,
+ None,
+ 'visualizing-the-tree-the-moons'),
+ ('Other ways of visualizing the trees',
+ 2,
+ None,
+ 'other-ways-of-visualizing-the-trees'),
+ ('Printing out as text', 2, None, 'printing-out-as-text'),
+ ('Algorithms for Setting up Decision Trees',
+ 2,
+ None,
+ 'algorithms-for-setting-up-decision-trees'),
+ ('The CART algorithm for Classification',
+ 2,
+ None,
+ 'the-cart-algorithm-for-classification'),
+ ('The CART algorithm for Regression',
+ 2,
+ None,
+ 'the-cart-algorithm-for-regression'),
+ ('Computing the Gini index', 2, None, 'computing-the-gini-index'),
+ ('Simple Python Code to read in Data and perform Classification',
+ 2,
+ None,
+ 'simple-python-code-to-read-in-data-and-perform-classification'),
+ ('Computing the Gini Factor',
+ 2,
+ None,
+ 'computing-the-gini-factor'),
+ ('Entropy and the ID3 algorithm',
+ 2,
+ None,
+ 'entropy-and-the-id3-algorithm'),
+ ('Cancer Data again now with Decision Trees and other Methods',
+ 2,
+ None,
+ 'cancer-data-again-now-with-decision-trees-and-other-methods'),
+ ('Another example, the moons again',
+ 2,
+ None,
+ 'another-example-the-moons-again'),
+ ('Playing around with regions',
+ 2,
+ None,
+ 'playing-around-with-regions'),
+ ('Regression trees', 2, None, 'regression-trees'),
+ ('Final regressor code', 2, None, 'final-regressor-code'),
+ ('Why Voting?', 2, None, 'why-voting'),
+ ('Tossing coins', 2, None, 'tossing-coins'),
+ ('Standard imports first', 2, None, 'standard-imports-first'),
+ ('Simple Voting Example, head or tail',
+ 2,
+ None,
+ 'simple-voting-example-head-or-tail'),
+ ('Using the Voting Classifier',
+ 2,
+ None,
+ 'using-the-voting-classifier'),
+ ('Voting and Bagging', 2, None, 'voting-and-bagging'),
+ ('Random forests', 2, None, 'random-forests'),
+ ('Random Forest Algorithm', 2, None, 'random-forest-algorithm'),
+ ('Random Forests Compared with other Methods on the Cancer Data',
+ 2,
+ None,
+ 'random-forests-compared-with-other-methods-on-the-cancer-data'),
+ ('Compare Bagging on Trees with Random Forests',
+ 2,
+ None,
+ 'compare-bagging-on-trees-with-random-forests')]}
end of tocinfo -->
@@ -268,7 +320,7 @@ MathJax.Hub.Config({
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+Week 44: Decision Trees, Ensemble methods and Random Forests
@@ -284,7 +336,7 @@ MathJax.Hub.Config({
-Aug 23, 2022
+Oct 30, 2022
@@ -292,16 +344,14 @@ MathJax.Hub.Config({
Overview of week 44
- Thursday: Wrapping up PCA from last week, Clustering and basics of decision trees, classification and regression algorithms
- Friday: Decision trees, voting models and bagging
+ Thursday: Basics of decision trees, classification and regression algorithms
+ Friday: Decision trees and ensemble models (bagging and random forests)
@@ -311,7 +361,6 @@ MathJax.Hub.Config({
Decision Trees: Geron's chapter 6 covers decision trees while ensemble models, voting and bagging are discussed in chapter 7. See also lecture from STK-IN4300, lecture 7 . Chapter 9.2 of Hastie et al contains also a good discussion.
- Clustering and PCA, see Geron's chapter 8 and Lecture notes . Bishop's chapter 9.1 is also a good read.
@@ -461,641 +510,6 @@ plt.show()
-
-
Learning Rate and more
-
-
When developing your own gradient descent code, it is useful to test
-it first on a standard ordinary least squares problem. Then the
-Hessian matrix is determined by the design matrix only, namely
-\( \boldsymbol{H}\propto \boldsymbol{X}^T\boldsymbol{X} \).
-
-
-
The optimal learning rate is determined by the inverse of the largest
-eigenvalue of \( \boldsymbol{H} \). This can be used as a guideline for the
-learning rate guess.
-
-
-
Keeping this fixed, can aid in studyng the dependence on say the mean
-square value for OLS as function of the number of batches and epochs
-in your stochastic gradient descent code. See for example the code
-examples for week 40 (right before the neural network material).
-
-
-
-
Thursday, Principal Component Analysis
-
-
For the principal component analysis,
-see slides from week 43 , in particular from slide 28 and forward
-
-
-
-
A kind of Bird's view on PCA
-
-
Why do we maximize variance during Principal Component Analysis?
-
-
Variance is a measure of the variability of the data you
-have. Potentially the number of components is infinite, so you want to "squeeze" the most
-information in each component of the finite set you build.
-
-
-
If, to exaggerate, you were to select a single principal component,
-you would want it to account for the most variability possible: hence
-the search for maximum variance, so that the one component collects
-the most "uniqueness" from the data set.
-
-
-
Maximizing the component vector variances is the same as maximizing
-the 'uniqueness' of those vectors. The vectors are as distant
-from each other as possible (orthogonal to each other).
-
-
-
Take for example a situation where you have 2 lines that are
-orthogonal in a 3D space. You can capture the environment much more
-completely with those orthogonal lines than 2 lines that are parallel
-(or nearly parallel). When applied to very high dimensional states
-using very few vectors, this becomes a much more important
-relationship among the vectors to maintain. In a linear algebra sense
-you want independent rows to be produced by PCA, otherwise some of
-those rows will be redundant.
-
-
-
-
Thursday: Clustering and Unsupervised Learning
-
-
In general terms cluster analysis, or clustering, is the task of grouping a
-data-set into different distinct categories based on some measure of equality of
-the data. This measure is often referred to as a metric or similarity
-measure in the literature (note: sometimes we deal with a dissimilarity
-measure instead). Usually, these metrics are formulated as some kind of
-distance function between points in a high-dimensional space.
-
-
-
The simplest, and also the most
-common is the Euclidean distance .
-
-
-
-
Basic Idea of the \( k \)-means Clustering Algorithm
-
-
The simplest of all clustering algorithms is the k-means algorithm
-, sometimes also referred to as Lloyds algorithm . It is the simplest and also
-the most common. From its simplicity it obtains both strengths and weaknesses.
-These will be discussed in more detail later. The \( k \)-means algorithm is a
-centroid based clustering algorithm.
-
-
-
-
The \( k \)-means Algorithm
-
-
Assume, we are given \( n \) data points and we wish to split the data into \( K < n \)
-different categories, or clusters. We label each cluster by an integer
-
-
-$$ k\in\{1, \cdots, K \}.
-$$
-
-
In the basic k-means algorithm each point is assigned to only
-one cluster \( k \), and these assignments are non-injective i.e. many-to-one. We
-can think of these mappings as an encoder \( k = C(i) \), which assigns the \( i \)-th
-data-point \( \bf x_i \) to the \( k \)-th cluster.
-
-
-
\( k \)-means algorithm in words:
-
- We start with guesses / random initializations of our \( k \) cluster centers/centroids
- For each centroid the points that are most similar are identified
- Then we move / replace each centroid with a coordinate average of all the points that were assigned to that centroid.
- Iterate 2-3 until the centroids no longer move (to some tolerance)
-
-
-
Basic Math of the \( k \)-means Algorithm
-
-
We assume we have \( n \) data-points
-$$
-\begin{equation}\label{eq:kmeanspoints}
- \boldsymbol{x_i} = \{x_{i, 1}, \cdots, x_{i, p}\}\in\mathbb{R}^p.
-\end{equation}
-$$
-
-
which we wish to group into \( K < n \) clusters. For our dissimilarity measure we
-use the squared Euclidean distance
-
-$$
-\begin{equation}\label{eq:squaredeuclidean}
- d(\boldsymbol{x_i}, \boldsymbol{x_i'}) = \sum_{j=1}^p(x_{ij} - x_{i'j})^2
- = ||\boldsymbol{x_i} - \boldsymbol{x_{i'}}||^2
-\end{equation}
-$$
-
-
-
-
Within Cluster Point Scatter
-
-
We define the so called within-cluster point scatter which gives us a
-measure of how close each data point assigned to the same cluster tends to be to
-the all the others.
-
-$$
-\begin{equation}\label{eq:withincluster}
- W(C) = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k}
- \sum_{C(i')=k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) =
- \sum_{k=1}^KN_k\sum_{C(i)=k}||\boldsymbol{x_i} - \boldsymbol{\overline{x_k}}||^2
-\end{equation}
-$$
-
-
where \( \boldsymbol{\overline{x_k}} \) is the mean vector associated with the \( k \)-th
-cluster, and \( N_k = \sum_{i=1}^nI(C(i) = k) \), where the \( I() \) notation is
-similar to the Kronecker delta (Commonly used in statistics, it just means that
-when \( i = k \) we have the encoder \( C(i) \) ). In other words, the within-cluster
-scatter measures the compactness of each cluster with respect to the data points
-assigned to each cluster. This is the quantity that the \( k \)-means algorithm aims
-to minimize. We refer to this quantity \( W(C) \) as the within cluster scatter
-because of its relation to the total scatter .
-
-
-
-
More Details
-
-
We have
-$$
-\begin{equation}\label{eq:totalscatter}
- T = W(C) + B(C) = \frac{1}{2}\sum_{i=1}^n
- \sum_{i'=1}^nd(\boldsymbol{x_i}, \boldsymbol{x_{i'}})
- = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k}
- \Big(\sum_{C(i') = k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})
- + \sum_{C(i')\neq k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})\Big).
-\end{equation}
-$$
-
-
This is a quantity that is conserved throughout the \( k \)-means algorithm. It can
-be thought of as the total amount of information in the data, and it is composed
-of the aforementioned within-cluster scatter and the between-cluster scatter
-\( B(C) \). In methods such as principle component analysis the total scatter is not
-conserved.
-
-
-
-
Total Cluster Variance
-
Given a cluster mean \( \boldsymbol{m_k} \) we define the total cluster variance
-$$
-\begin{equation}\label{eq:totalclustervariance}
- \min_{C, \{\boldsymbol{m_k}\}_1^K}\sum_{k=1}^KN_k\sum||\boldsymbol{x_i} - \boldsymbol{m_k}||^2
-\end{equation}
-$$
-
-
Now we have all the pieces necessary to formally revisit the \( k \)-means algorithm.
-
-
-
The \( k \)-means Clustering Algorithm
-
-
The \( k \)-means clustering algorithm goes as follows
-
-
- For a given cluster assignment \( C \), and \( k \) cluster means \( \left\{m_1, \cdots, m_k\right\} \). We minimize the total cluster variance with respect to the cluster means \( \{m_k\} \) yielding the means of the currently assigned clusters.
- Given a current set of \( k \) means \( \{m_k\} \) the total cluster variance is minimized by assigning each observation to the closest (current) cluster mean. That is $$C(i) = \underset{1\leq k\leq K}{\mathrm{argmin}} ||\boldsymbol{x_i} - \boldsymbol{m_k}||^2$$
- Steps 1 and 2 are repeated until the assignments do not change.
-
-
-
Summarizing
-
-
- Before we start we specify a number \( k \) which is the number of clusters we want to try to separate our data into.
- We initially choose \( k \) random data points in our data as our initial centroids, or means (this is where the name comes from).
- Assign each data point to their closest centroid, based on the squared Euclidean distance.
- For each of the \( k \) cluster we update the centroid by calculating new mean values for all the data points in the cluster.
- Iteratively minimize the within cluster scatter by performing steps (3, 4) until the new assignments stop changing (can be to some tolerance) or until a maximum number of iterations have passed.
-
-
-
Writing our own Code, the Data Set
-
-
Let us now program the most basic version of the algorithm using nothing but
-Python with numpy arrays. This code is kept intentionally simple to gradually
-progress our understanding. There is no vectorization of any kind, and even most
-helper functions are not utilized.
-
-
-
We need first a dataset to do our cluster analysis on. In our case
-this is a plain vanilla data set using random numbers using a
-Gaussian distribution.
-
-
-
-
-
-
-
Next we define functions, for ease of use later, to generate Gaussians and to
-set up our toy data set.
-
-
-
-
-
-
-
-
Implementing the \( k \)-means Algorithm
-
-
With the above dataset we start
-implementing the \( k \)-means algorithm.
-
-
-
-
-
-
-
-
-
Plotting
-
-
-
-
-
So what do we have so far? We have 'picked' \( k \) centroids at random from our
-data points. There are other ways of more intelligently choosing their
-initializations, however for our purposes randomly is fine. Then we have
-initialized an array 'distances' which holds the information of the distance,
-or dissimilarity , of every point to of our centroids. Finally, we have
-initialized an array 'cluster_labels' which according to our distances array
-holds the information of to which centroid every point is assigned. This was the
-first pass of our algorithm. Essentially, all we need to do now is repeat the
-distance and assignment steps above until we have reached a desired convergence
-or a maximum amount of iterations.
-
-
-
-
Continuing
-
-
-
-
-
-
-
-
Wrapping it up
-
We now have a simple , un-optimized \( k \)-means
-clustering implementation. Lets plot the final result
-
-
-
-
-
-
-
-
-
-
-
Decision trees, overarching aims
@@ -2958,6 +2372,1613 @@ plt.show()
+
+
Why binary splits?
+
+
It is custom to split to a tree uising binary splits. The reason is
+that multiway splits fragment the data too quickly, leaving
+insufficient data at the next level down. Multiway splits can be
+achieved by a series of binary split and this is normally preferred.
+
+
+
+
Computing a Tree using the Gini Index
+
+
Consider the following example with attributes/features and two
+possible outcomes (classes) for each attribute. Assume we wish to find some
+correlations between the average grade of a student as function of the
+number of hours studied and hours slept. We want also to correlate the
+grade in a given course with the general trend, whether the students
+recently has gotten grades below average or above.
+
+
+
We have three features/attributes
+
+ Trend of average grades before present course, classified as either below or above the average grade of the whole class
+ The number of hours studies, classified again as either higher (more than 3 hours per day) or lower . Here we have used a standard for one \( ECTS \) which is scaled to 25-30 hours of work for a semester which lasts 18 weeks, with 15 weeks of lectures and 3 weeks for exams, assuming a total of 30 ECTS per semester.
+ The number of hours slept as high for more than \( 8 \) hours and below for less than 8 hours of sleep, classified again as either high or low
+ The final grade whether it is above or below average
+
+
+
The Table
+
+
+
+Grade Trend Hours slept Hours Studied Grade
+
+
+ Above Low High Above
+ Below High Low Below
+ Above Low High Above
+ Above High High Above
+ Below Low High Below
+ Above Low Low Below
+ Below High High Below
+ Below Low High Below
+ Above Low Low Below
+ Above High High Above
+
+
+
+
+
Computing the various Gini Indices
+
+
In computations we will translate all classes into numbers. Being
+these binary classes, they can easily be split into ones and zeros.
+
+
+
+
Gini index for Average trend
+
+
See handwritten notes for Thursday November 11
+
+
+
+
+
Computing the various Gini Indices, Hours slept
+
+
+
Gini index for hour slept
+
+
See handwritten notes for Thursday November 11
+
+
+
+
+
Computing the various Gini Indices, Hours studied
+
+
+
Gini index for hour studied
+
+
See handwritten notes for Thursday November 11
+
+
+
+
For final tree, see the above handwritten notes
+
+
+
A possible code using Scikit-Learn
+
+
+
+
+
+
+
+
Visualizing Trees, More examples
+
+
+
+
+
+
+
Visualizing the Tree, The Moons
+
+
+
+
+
+
+
Other ways of visualizing the trees
+
+
Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.
+
+
+
+
+
+
+
+
Printing out as text
+
+
Alternatively, the tree can also be exported in textual format with the function exporttext.
+This method doesn’t require the installation of external libraries and is more compact:
+
+
+
+
+
+
+
+
+
Algorithms for Setting up Decision Trees
+
+
Two algorithms stand out in the set up of decision trees:
+
+ The CART (Classification And Regression Tree) algorithm for both classification and regression
+ The ID3 algorithm based on the computation of the information gain for classification
+
+
We discuss both algorithms with applications here. The popular library
+Scikit-Learn uses the CART algorithm. For classification problems
+you can use either the gini index or the entropy to split a tree
+in two branches.
+
+
+
+
The CART algorithm for Classification
+
+
For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \).
+This could be for example a threshold set by a number below a certain circumference of a malign tumor.
+
+
+
How do we find these two quantities?
+We search for the pair \( (k,t_k) \) that produces the purest subset using for example the gini factor \( G \).
+The cost function it tries to minimize is then
+
+$$
+C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}},
+$$
+
+
where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \)
+ is the number of instances in the left/right subset
+
+
+
Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets
+and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the
+\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other
+hyperparameters control additional stopping conditions such as the \( min\_samples\_split \),
+\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).
+
+
+
+
The CART algorithm for Regression
+
+
The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the
+training set in a way that minimizes say the gini or entropy impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now
+
+$$
+C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}.
+$$
+
+
Here the MSE for a specific node is defined as
+$$
+\mathrm{MSE}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}(\overline{y}_{\mathrm{node}}-y_i)^2,
+$$
+
+
with
+$$
+\overline{y}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}y_i,
+$$
+
+
the mean value of all observations in a specific node.
+
+
Without any regularization, the regression task for decision trees,
+just like for classification tasks, is prone to overfitting.
+
+
+
+
Computing the Gini index
+
+
The example we will look at is a classical one in many Machine
+Learning applications. Based on various meteorological features, we
+have several so-called attributes which decide whether we at the end
+will do some outdoor activity like skiing, going for a bike ride etc
+etc. The table here contains the feautures outlook , temperature ,
+humidity and wind . The target or output is whether we ride
+(True=1) or whether we do something else that day (False=0). The
+attributes for each feature are then sunny, overcast and rain for the
+outlook, hot, cold and mild for temperature, high and normal for
+humidity and weak and strong for wind.
+
+
+
The table here summarizes the various attributes and
+
+
+Day Outlook Temperature Humidity Wind Ride
+
+
+ 1 Sunny Hot High Weak 0
+ 2 Sunny Hot High Strong 1
+ 3 Overcast Hot High Weak 1
+ 4 Rain Mild High Weak 1
+ 5 Rain Cool Normal Weak 1
+ 6 Rain Cool Normal Strong 0
+ 7 Overcast Cool Normal Strong 1
+ 8 Sunny Mild High Weak 0
+ 9 Sunny Cool Normal Weak 1
+ 10 Rain Mild Normal Weak 1
+ 11 Sunny Mild Normal Strong 1
+ 12 Overcast Mild High Strong 1
+ 13 Overcast Hot Normal Weak 1
+ 14 Rain Mild High Strong 0
+
+
+
+
+
+
+
+
+
+
+
+
+
Computing the Gini Factor
+
+
The above functions (gini, entropy and misclassification error) are
+important components of the so-called CART algorithm. We will discuss
+this algorithm below after we have discussed the information gain
+algorithm ID3.
+
+
+
In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.
+
+
+
+
+
+
+
+
Entropy and the ID3 algorithm
+
+
The ID3 algorithm learns decision trees by constructing
+them in a top down way, beginning with the question which attribute should be tested at the root of the tree ?
+
+
+
+ Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.
+ The best attribute is selected and used as the test at the root node of the tree.
+ A descendant of the root node is then created for each possible value of this attribute.
+ Training examples are sorted to the appropriate descendant node.
+ The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.
+ This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.
+
+
The ID3 algorithm selects which attribute to test at each node in the
+tree.
+
+
+
We would like to select the attribute that is most useful for classifying
+examples.
+
+
+
What is a good quantitative measure of the worth of an attribute?
+
+
Information gain measures how well a given attribute separates the
+training examples according to their target classification.
+
+
+
The ID3 algorithm uses this information gain measure to select among the candidate
+attributes at each step while growing the tree.
+
+
+
+
Cancer Data again now with Decision Trees and other Methods
+
+
+
+
+
+
+
Another example, the moons again
+
+
+
+
+
+
+
Playing around with regions
+
+
+
+
+
+
+
Regression trees
+
+
+
+
+
+
+
+
+
+
+
Final regressor code
+
+
+
+
+
+
+
+
+
+
+
Why Voting?
+
+
The idea behind boosting, and voting as well can be phrased as follows:
+Can a group of people somehow arrive at highly
+reasoned decisions, despite the weak judgement of the individual
+members?
+
+
+
The aim is to create a good classifier by combining several weak classifiers.
+A weak classifier is a classifier which is able to produce results that are only slightly better than guessing at random.
+
+
+
The basic approach is to apply repeatedly (in boosting this is done in an iterative way) a weak classifier to modifications of the data.
+In voting we simply apply the law of large numbers while in boosting we give more weight to misclassified data in
+each iteration.
+
+
+
Decision trees play an important role as our weak classifier. They serve as the basic method.
+
+
+
Tossing coins
+
+
The simplest case is a so-called voting ensemble. To illustrate this,
+think of yourself tossing coins with a biased outcome of 51 per cent
+for heads and 49% for tails. With only few tosses,
+you may not clearly see this distribution for heads and tails. However, after some
+thousands of tosses, there will be a clear majority of heads. With 2000 tosses
+you should see approximately 1020 heads and 980 tails.
+
+
+
We can then state that the outcome is a clear majority of heads. If
+you do this ten thousand times, it is easy to see that there is a 97%
+likelihood of a majority of heads.
+
+
+
Another example would be to collect all polls before an
+election. Different polls may show different likelihoods for a
+candidate winning with say a majority of the popular vote. The majority vote
+would then consist in many polls indicating that this candidate will
+actually win.
+
+
+
The example here shows how we can implement the coin tossing case,
+clealry demostrating that after some tosses we see the law of large
+numbers kicking in.
+
+
+
+
Standard imports first
+
+
+
+
+
+
+
+
Simple Voting Example, head or tail
+
+
+
+
+
+
+
Using the Voting Classifier
+
+
We can use the voting classifier on other data sets, here the exciting binary case of two distinct objects using the make moons functionality of Scikit-Learn .
+
+
+
+
+
+
+
Voting and Bagging
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Random forests
+
+
Random forests provide an improvement over bagged trees by way of a
+small tweak that decorrelates the trees.
+
+
+
As in bagging, we build a
+number of decision trees on bootstrapped training samples. But when
+building these decision trees, each time a split in a tree is
+considered, a random sample of \( m \) predictors is chosen as split
+candidates from the full set of \( p \) predictors. The split is allowed to
+use only one of those \( m \) predictors.
+
+
+
A fresh sample of \( m \) predictors is
+taken at each split, and typically we choose
+
+
+$$
+m\approx \sqrt{p}.
+$$
+
+
In building a random forest, at
+each split in the tree, the algorithm is not even allowed to consider
+a majority of the available predictors.
+
+
+
The reason for this is rather clever. Suppose that there is one very
+strong predictor in the data set, along with a number of other
+moderately strong predictors. Then in the collection of bagged
+variable importance random forest trees, most or all of the trees will
+use this strong predictor in the top split. Consequently, all of the
+bagged trees will look quite similar to each other. Hence the
+predictions from the bagged trees will be highly correlated.
+Unfortunately, averaging many highly correlated quantities does not
+lead to as large of a reduction in variance as averaging many
+uncorrelated quantities. In particular, this means that bagging will
+not lead to a substantial reduction in variance over a single tree in
+this setting.
+
+
+
+
Random Forest Algorithm
+
The algorithm described here can be applied to both classification and regression problems.
+
+
We will grow of forest of say \( B \) trees.
+
+ For \( b=1:B \)
+
+ Draw a bootstrap sample from the training data organized in our \( \boldsymbol{X} \) matrix.
+ We grow then a random forest tree \( T_b \) based on the bootstrapped data by repeating the steps outlined till we reach the maximum node size is reached
+
+ we select \( m \le p \) variables at random from the \( p \) predictors/features
+ pick the best split point among the \( m \) features using for example the CART algorithm and create a new node
+ split the node into daughter nodes
+
+
+ Output then the ensemble of trees \( \{T_b\}_1^{B} \) and make predictions for either a regression type of problem or a classification type of problem.
+
+
+
Random Forests Compared with other Methods on the Cancer Data
+
+
+
+
+
Recall that the cumulative gains curve shows the percentage of the
+overall number of cases in a given category gained by targeting a
+percentage of the total number of cases.
+
+
+
Similarly, the receiver operating characteristic curve, or ROC curve,
+displays the diagnostic ability of a binary classifier system as its
+discrimination threshold is varied. It plots the true positive rate against the false positive rate.
+
+
+
+
Compare Bagging on Trees with Random Forests
+
+
+
+
+
+
+
+
+
© 1999-2022, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license
diff --git a/doc/pub/week44/html/week44.html b/doc/pub/week44/html/week44.html
index cfeedb86b..c910b1e24 100644
--- a/doc/pub/week44/html/week44.html
+++ b/doc/pub/week44/html/week44.html
@@ -8,8 +8,8 @@ doconce format html week44.do.txt --pygments_html_style=default --html_style=blo
-
-Week 44: Dimensionality Reduction, PCA and Clustering. Decision Trees
+
+Week 44: Decision Trees, Ensemble methods and Random Forests