From ddb39b03cf1fa921b34069f6af14de98216ac53c Mon Sep 17 00:00:00 2001 From: mhjensen Date: Fri, 25 Oct 2019 06:00:25 +0200 Subject: [PATCH] added example --- .../html/._DecisionTrees-bs000.html | 62 ++-- .../html/._DecisionTrees-bs001.html | 60 ++-- .../html/._DecisionTrees-bs002.html | 60 ++-- .../html/._DecisionTrees-bs003.html | 60 ++-- .../html/._DecisionTrees-bs004.html | 72 ++-- .../html/._DecisionTrees-bs005.html | 60 ++-- .../html/._DecisionTrees-bs006.html | 60 ++-- .../html/._DecisionTrees-bs007.html | 60 ++-- .../html/._DecisionTrees-bs008.html | 60 ++-- .../html/._DecisionTrees-bs009.html | 62 ++-- .../html/._DecisionTrees-bs010.html | 62 ++-- .../html/._DecisionTrees-bs011.html | 60 ++-- .../html/._DecisionTrees-bs012.html | 62 ++-- .../html/._DecisionTrees-bs013.html | 62 ++-- .../html/._DecisionTrees-bs014.html | 183 ++++------ .../html/._DecisionTrees-bs015.html | 62 ++-- .../html/._DecisionTrees-bs016.html | 60 ++-- .../html/._DecisionTrees-bs017.html | 60 ++-- .../html/._DecisionTrees-bs018.html | 60 ++-- .../html/._DecisionTrees-bs019.html | 94 ++--- .../html/._DecisionTrees-bs020.html | 78 ++-- .../html/._DecisionTrees-bs021.html | 107 +++--- .../html/._DecisionTrees-bs022.html | 112 +++--- .../html/._DecisionTrees-bs023.html | 113 +++--- .../html/._DecisionTrees-bs024.html | 109 +++--- .../html/._DecisionTrees-bs025.html | 121 ++++--- .../html/._DecisionTrees-bs026.html | 134 +++---- .../html/._DecisionTrees-bs027.html | 124 +++---- .../html/._DecisionTrees-bs028.html | 83 ++--- .../DecisionTrees/html/DecisionTrees-bs.html | 62 ++-- .../html/DecisionTrees-reveal.html | 196 ++++------ .../html/DecisionTrees-solarized.html | 224 ++++-------- doc/pub/DecisionTrees/html/DecisionTrees.html | 224 ++++-------- .../DecisionTrees/ipynb/DecisionTrees.ipynb | 335 +++++++----------- .../ipynb/ipynb-DecisionTrees-src.tar.gz | Bin 194 -> 194 bytes .../pdf/DecisionTrees-minted.pdf | Bin 262866 -> 262491 bytes doc/src/DecisionTrees/DecisionTrees.do.txt | 166 +++------ doc/src/DecisionTrees/cancer.py | 41 +++ 38 files changed, 1564 insertions(+), 2046 deletions(-) create mode 100644 doc/src/DecisionTrees/cancer.py diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html index a0cf685f0..a1f2bc91d 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs000.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -176,7 +174,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Oct 24, 2019

    +

    Oct 25, 2019


    @@ -200,7 +198,7 @@ MathJax.Hub.Config({

  • 9
  • 10
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs001.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs001.html index aca7dd021..d62144044 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs001.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs001.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -205,7 +203,7 @@ and leaf nodes which are then connected by branches.
  • 10
  • 11
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs002.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs002.html index 4325e1da4..0ebae0fe3 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs002.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs002.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -190,7 +188,7 @@ Then we are essentially done!
  • 11
  • 12
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs003.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs003.html index ea02583d2..122519571 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs003.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs003.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -269,7 +267,7 @@ plt.show()
  • 12
  • 13
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs004.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs004.html index b82959053..a9383aaee 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs004.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs004.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -163,12 +161,7 @@ MathJax.Hub.Config({ There are mainly two steps
      -
    1. We split the predictor space (the set of possible values \( x_1,x_2,\dots, x_p \)) into \( J \)
    2. -
    - -distinct and non-non-overlapping regions, \( R_1,R_2,\dots,R_J \). - -
      +
    1. 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 \).
    2. 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 \).
    @@ -176,15 +169,14 @@ 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 predic- tive model. The goal is to find boxes \( R_1,\dots,R_J \) +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 the $j$th -box. +within box \( j \).

    @@ -206,7 +198,7 @@ box.

  • 13
  • 14
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs005.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs005.html index b71aa18b4..5b7eb2fcb 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs005.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs005.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -194,7 +192,7 @@ better tree in some future step.
  • 14
  • 15
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs006.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs006.html index 16e303e1f..d42df5226 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs006.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs006.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -223,7 +221,7 @@ region contains more than five observations.
  • 15
  • 16
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs007.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs007.html index 5108d19bc..31a18c127 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs007.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs007.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -196,7 +194,7 @@ parameter \( \alpha \).
  • 16
  • 17
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs008.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs008.html index 62f58548f..3180d0399 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs008.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs008.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -209,7 +207,7 @@ subtree corresponding to \( \alpha \).
  • 17
  • 18
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs009.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs009.html index e5fed5a4b..2b476d903 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs009.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs009.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,7 +155,7 @@ MathJax.Hub.Config({ -

    A schematic procedure

    +

    Schematic Regression Procedure

    @@ -206,7 +204,7 @@ MathJax.Hub.Config({
  • 18
  • 19
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs010.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs010.html index 24b2522be..6418b4ffe 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs010.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs010.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,7 +155,7 @@ MathJax.Hub.Config({ -

    A classification tree

    +

    A Classification Tree

    A classification tree is very similar to a regression tree, except @@ -199,7 +197,7 @@ fall into that region.

  • 19
  • 20
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs011.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs011.html index 47ae20d8d..4d545ac98 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs011.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs011.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -204,7 +202,7 @@ than is the classification error rate.
  • 20
  • 21
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs012.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs012.html index 5ec800104..6d018f0bb 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs012.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs012.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -158,6 +156,8 @@ 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. @@ -222,7 +222,7 @@ $$

  • 21
  • 22
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs013.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs013.html index 72b7a0f29..1b60813c2 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs013.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs013.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -160,7 +158,7 @@ MathJax.Hub.Config({

    Entropy and the ID3 algorithm

    -More text to come here. +More text and code to come here.

    @@ -188,7 +186,7 @@ More text to come here.

  • 22
  • 23
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs014.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs014.html index 4f5db444f..fbf72f5b6 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs014.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs014.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,94 +155,51 @@ MathJax.Hub.Config({ -

    Writing your own code for a classification tree

    - +

    Cancer Data again now with Decision Trees

    -

    def entropy(target_col):
    -    """
    -    Calculate the entropy of a dataset.
    -    The only parameter of this function is the target_col parameter which specifies the target column
    -    """
    -    elements,counts = np.unique(target_col,return_counts = True)
    -    entropy = np.sum([(-counts[i]/np.sum(counts))*np.log2(counts[i]/np.sum(counts)) for i in range(len(elements))])
    -    return entropy
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.model_selection import  train_test_split 
    +from sklearn.datasets import load_breast_cancer
    +from sklearn.svm import SVC
    +from sklearn.linear_model import LogisticRegression
    +from sklearn.tree import DecisionTreeClassifier
     
    -def InfoGain(data,split_attribute_name,target_name="class"):
    -    """
    -    Calculate the information gain of a dataset. This function takes three parameters:
    -    1. data = The dataset for whose feature the IG should be calculated
    -    2. split_attribute_name = the name of the feature for which the information gain should be calculated
    -    3. target_name = the name of the target feature. The default for this example is "class"
    -    """    
    -    #Calculate the entropy of the total dataset
    -    total_entropy = entropy(data[target_name])
    -    
    -    ##Calculate the entropy of the dataset
    -    
    -    #Calculate the values and the corresponding counts for the split attribute 
    -    vals,counts= np.unique(data[split_attribute_name],return_counts=True)
    -    
    -    #Calculate the weighted entropy
    -    Weighted_Entropy = np.sum([(counts[i]/np.sum(counts))*entropy(data.where(data[split_attribute_name]==vals[i]).dropna()[target_name]) for i in range(len(vals))])
    -    
    -    #Calculate the information gain
    -    Information_Gain = total_entropy - Weighted_Entropy
    -    return Information_Gain
    -       
    +# Load the data
    +cancer = load_breast_cancer()
     
    -def ID3(data,originaldata,features,target_attribute_name="class",parent_node_class = None):
    -    #Define the stopping criteria --> If one of this is satisfied, we want to return a leaf node#
    -    
    -    #If all target_values have the same value, return this value
    -    if len(np.unique(data[target_attribute_name])) <= 1:
    -        return np.unique(data[target_attribute_name])[0]
    -    
    -    #If the dataset is empty, return the mode target feature value in the original dataset
    -    elif len(data)==0:
    -        return np.unique(originaldata[target_attribute_name])[np.argmax(np.unique(originaldata[target_attribute_name],return_counts=True)[1])]
    -    
    -    #If the feature space is empty, return the mode target feature value of the direct parent node --> Note that
    -    #the direct parent node is that node which has called the current run of the ID3 algorithm and hence
    -    #the mode target feature value is stored in the parent_node_class variable.
    -    
    -    elif len(features) ==0:
    -        return parent_node_class
    -    
    -    #If none of the above holds true, grow the tree!
    -    
    -    else:
    -        #Set the default value for this node --> The mode target feature value of the current node
    -        parent_node_class = np.unique(data[target_attribute_name])[np.argmax(np.unique(data[target_attribute_name],return_counts=True)[1])]
    -        
    -        #Select the feature which best splits the dataset
    -        item_values = [InfoGain(data,feature,target_attribute_name) for feature in features] #Return the information gain values for the features in the dataset
    -        best_feature_index = np.argmax(item_values)
    -        best_feature = features[best_feature_index]
    -        
    -        #Create the tree structure. The root gets the name of the feature (best_feature) with the maximum information
    -        #gain in the first run
    -        tree = {best_feature:{}}
    -        
    -        
    -        #Remove the feature with the best inforamtion gain from the feature space
    -        features = [i for i in features if i != best_feature]
    -        
    -        #Grow a branch under the root node for each possible value of the root node feature
    -        
    -        for value in np.unique(data[best_feature]):
    -            value = value
    -            #Split the dataset along the value of the feature with the largest information gain and therwith create sub_datasets
    -            sub_data = data.where(data[best_feature] == value).dropna()
    -            
    -            #Call the ID3 algorithm for each of those sub_datasets with the new parameters --> Here the recursion comes in!
    -            subtree = ID3(sub_data,dataset,features,target_attribute_name,parent_node_class)
    -            
    -            #Add the sub tree, grown from the sub_dataset to the tree under the root node
    -            tree[best_feature][value] = subtree
    -            
    -        return(tree)    
    +X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
    +print(X_train.shape)
    +print(X_test.shape)
    +# Logistic Regression
    +logreg = LogisticRegression(solver='lbfgs')
    +logreg.fit(X_train, y_train)
    +print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
    +# Support vector machine
    +svm = SVC(gamma='auto', C=100)
    +svm.fit(X_train, y_train)
    +print("Test set accuracy with SVM: {:.2f}".format(svm.score(X_test,y_test)))
    +# Decision Trees
    +deep_tree_clf = DecisionTreeClassifier(max_depth=None)
    +deep_tree_clf.fit(X_train, y_train)
    +print("Test set accuracy with Decision Trees: {:.2f}".format(deep_tree_clf.score(X_test,y_test)))
    +#now scale the data
    +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)
    +# Logistic Regression
    +logreg.fit(X_train_scaled, y_train)
    +print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
    +# Support Vector Machine
    +svm.fit(X_train_scaled, y_train)
    +print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
    +# Decision Trees
    +deep_tree_clf.fit(X_train_scaled, y_train)
    +print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
     

    @@ -272,7 +227,7 @@ MathJax.Hub.Config({

  • 23
  • 24
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs015.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs015.html index 7e14bb536..f67614dbf 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs015.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs015.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,7 +155,7 @@ MathJax.Hub.Config({ -

    Back to moons again

    +

    Another example, the moons again

    @@ -252,7 +250,7 @@ plt.show()

  • 24
  • 25
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs016.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs016.html index 5d4fb0a2c..3cb295cec 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs016.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs016.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -208,7 +206,7 @@ plt.show()
  • 25
  • 26
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs017.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs017.html index ec193ce57..52cfbfa50 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs017.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs017.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -202,7 +200,7 @@ tree_reg.fit(X, y)
  • 26
  • 27
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs018.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs018.html index 98b2ef9dd..4a152e67f 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs018.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs018.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -258,7 +256,7 @@ plt.show()
  • 27
  • 28
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs019.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs019.html index 506826513..02d40e42e 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs019.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs019.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,32 +155,18 @@ MathJax.Hub.Config({ -

    Classification again: The zoo data

    -

    +

    Pros and cons of trees, pros

    - -
    import pandas as pd
    -import numpy as np
    -from pprint import pprint
    -from sklearn.tree import DecisionTreeClassifier
    +
      +
    • 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)
    • +
    -#Import the dataset -dataset = pd.read_csv('data/zoo.csv') -#We drop the animal names since this is not a good feature to split the data on -#dataset=dataset.drop('animal_name',axis=1) -#Split the data into a training and a testing set -train_features = dataset.iloc[:80,:-1] -test_features = dataset.iloc[80:,:-1] -train_targets = dataset.iloc[:80,-1] -test_targets = dataset.iloc[80:,-1] -#Train the model -tree = DecisionTreeClassifier(criterion = 'entropy').fit(train_features,train_targets) -#Predict the classes of new, unseen data -prediction = tree.predict(test_features) -#Check the accuracy -print("The prediction accuracy is: ",tree.score(test_features,test_targets)*100,"%") -
    -

      @@ -207,8 +191,6 @@ prediction = tree27
    • 28
    • 29
    • -
    • ...
    • -
    • 30
    • »
    diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs020.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs020.html index 9ab46fe5c..9bcb742f8 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs020.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs020.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,18 +155,21 @@ MathJax.Hub.Config({ -

    Pros and cons of trees, pros

    +

    Disadvantages

      -
    • 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)
    • +
    • 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. + +

      @@ -192,7 +193,6 @@ MathJax.Hub.Config({
    • 27
    • 28
    • 29
    • -
    • 30
    • »
    diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs021.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs021.html index 6fc473476..6598f41eb 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs021.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs021.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,19 +155,45 @@ MathJax.Hub.Config({ -

    Disadvantages

    +

    Bagging

    -
      -
    • 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
    • -
    +

    +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. -However, by aggregating many decision trees, using methods like bagging, random forests, and boosting, the predictive performance of trees can be substantially improved. +

    +Bootstrap aggregation, or just bagging, is a +general-purpose procedure for reducing the variance of a statistical +learning method. + +

    +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.

    @@ -194,7 +218,6 @@ However, by aggregating many decision trees, using methods like bagging, random

  • 27
  • 28
  • 29
  • -
  • 30
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs022.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs022.html index 6772a27cd..2660af6af 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs022.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs022.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,46 +155,23 @@ MathJax.Hub.Config({ -

    Bagging

    - +

    Simple example, head or tail

    -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. - -

    -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. + +

    heads_proba = 0.51
    +coin_tosses = (np.random.rand(10000, 10) < heads_proba).astype(np.int32)
    +cumulative_heads_ratio = np.cumsum(coin_tosses, axis=0) / np.arange(1, 10001).reshape(-1, 1)
    +plt.figure(figsize=(8,3.5))
    +plt.plot(cumulative_heads_ratio)
    +plt.plot([0, 10000], [0.51, 0.51], "k--", linewidth=2, label="51%")
    +plt.plot([0, 10000], [0.5, 0.5], "k-", label="50%")
    +plt.xlabel("Number of coin tosses")
    +plt.ylabel("Heads ratio")
    +plt.legend(loc="lower right")
    +plt.axis([0, 10000, 0.42, 0.58])
    +plt.show()
    +

    @@ -219,7 +194,6 @@ predictor, averaged over all \( B \) trees.

  • 27
  • 28
  • 29
  • -
  • 30
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs023.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs023.html index 25c3b3946..d32ea35dd 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs023.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs023.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,23 +155,45 @@ MathJax.Hub.Config({ -

    Simple example, head or tail

    -

    +

    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 +quanti- ties. In particular, this means that bagging will not lead to +a substantial reduction in variance over a single tree in this +setting. - -

    heads_proba = 0.51
    -coin_tosses = (np.random.rand(10000, 10) < heads_proba).astype(np.int32)
    -cumulative_heads_ratio = np.cumsum(coin_tosses, axis=0) / np.arange(1, 10001).reshape(-1, 1)
    -plt.figure(figsize=(8,3.5))
    -plt.plot(cumulative_heads_ratio)
    -plt.plot([0, 10000], [0.51, 0.51], "k--", linewidth=2, label="51%")
    -plt.plot([0, 10000], [0.5, 0.5], "k-", label="50%")
    -plt.xlabel("Number of coin tosses")
    -plt.ylabel("Heads ratio")
    -plt.legend(loc="lower right")
    -plt.axis([0, 10000, 0.42, 0.58])
    -plt.show()
    -

    @@ -195,7 +215,6 @@ plt.show()

  • 27
  • 28
  • 29
  • -
  • 30
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs024.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs024.html index cd6c1a0b1..8080d2514 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs024.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs024.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,45 +155,21 @@ MathJax.Hub.Config({ -

    Random forests

    - +

    A simple scikit-learn example

    -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 -quanti- ties. In particular, this means that bagging will not lead to -a substantial reduction in variance over a single tree in this -setting. + +

    from sklearn.ensemble import RandomForestClassifier
    +from sklearn.preprocessing import LabelEncoder
    +from sklearn.model_selection import cross_validate
    +# Data set not specificied
    +X = dataset.XXX
    +Y = dataset.YYY
    +#Instantiate the model with 100 trees and entropy as splitting criteria
    +Random_Forest_model = RandomForestClassifier(n_estimators=100,criterion="entropy")
    +#Cross validation
    +accuracy = cross_validate(Random_Forest_model,X,Y,cv=10)['test_score']
    +

    @@ -216,7 +190,6 @@ setting.

  • 27
  • 28
  • 29
  • -
  • 30
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs025.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs025.html index 2cd89ccce..d64c09e5b 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs025.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs025.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,20 +155,60 @@ MathJax.Hub.Config({ -

    A simple scikit-learn example

    +

    Please, not the moons again!

    -

    from sklearn.ensemble import RandomForestClassifier
    -from sklearn.preprocessing import LabelEncoder
    -from sklearn.model_selection import cross_validate
    -# Data set not specificied
    -X = dataset.XXX
    -Y = dataset.YYY
    -#Instantiate the model with 100 trees and entropy as splitting criteria
    -Random_Forest_model = RandomForestClassifier(n_estimators=100,criterion="entropy")
    -#Cross validation
    -accuracy = cross_validate(Random_Forest_model,X,Y,cv=10)['test_score']
    +
    from sklearn.model_selection import train_test_split
    +from sklearn.datasets import make_moons
    +
    +X, y = make_moons(n_samples=500, noise=0.30, random_state=42)
    +X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
    +from sklearn.ensemble import RandomForestClassifier
    +from sklearn.ensemble import VotingClassifier
    +from sklearn.linear_model import LogisticRegression
    +from sklearn.svm import SVC
    +
    +log_clf = LogisticRegression(random_state=42)
    +rnd_clf = RandomForestClassifier(random_state=42)
    +svm_clf = SVC(random_state=42)
    +
    +voting_clf = VotingClassifier(
    +    estimators=[('lr', log_clf), ('rf', rnd_clf), ('svc', svm_clf)],
    +    voting='hard')
    +voting_clf.fit(X_train, y_train)
    +
    +

    + + +

    from sklearn.metrics import accuracy_score
    +
    +for clf in (log_clf, rnd_clf, svm_clf, voting_clf):
    +    clf.fit(X_train, y_train)
    +    y_pred = clf.predict(X_test)
    +    print(clf.__class__.__name__, accuracy_score(y_test, y_pred))
    +
    +

    + + +

    log_clf = LogisticRegression(random_state=42)
    +rnd_clf = RandomForestClassifier(random_state=42)
    +svm_clf = SVC(probability=True, random_state=42)
    +
    +voting_clf = VotingClassifier(
    +    estimators=[('lr', log_clf), ('rf', rnd_clf), ('svc', svm_clf)],
    +    voting='soft')
    +voting_clf.fit(X_train, y_train)
    +
    +

    + + +

    from sklearn.metrics import accuracy_score
    +
    +for clf in (log_clf, rnd_clf, svm_clf, voting_clf):
    +    clf.fit(X_train, y_train)
    +    y_pred = clf.predict(X_test)
    +    print(clf.__class__.__name__, accuracy_score(y_test, y_pred))
     

    @@ -191,7 +229,6 @@ accuracy = cross_validate(Random_Forest_mode

  • 27
  • 28
  • 29
  • -
  • 30
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs026.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs026.html index ab42056d9..4ee762999 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs026.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs026.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,60 +155,63 @@ MathJax.Hub.Config({ -

    Please, not the moons again!

    +

    Bagging examples

    +

    -

    from sklearn.model_selection import train_test_split
    -from sklearn.datasets import make_moons
    +
    from sklearn.ensemble import BaggingClassifier
    +from sklearn.tree import DecisionTreeClassifier
     
    -X, y = make_moons(n_samples=500, noise=0.30, random_state=42)
    -X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
    -from sklearn.ensemble import RandomForestClassifier
    -from sklearn.ensemble import VotingClassifier
    -from sklearn.linear_model import LogisticRegression
    -from sklearn.svm import SVC
    -
    -log_clf = LogisticRegression(random_state=42)
    -rnd_clf = RandomForestClassifier(random_state=42)
    -svm_clf = SVC(random_state=42)
    -
    -voting_clf = VotingClassifier(
    -    estimators=[('lr', log_clf), ('rf', rnd_clf), ('svc', svm_clf)],
    -    voting='hard')
    -voting_clf.fit(X_train, y_train)
    +bag_clf = BaggingClassifier(
    +    DecisionTreeClassifier(random_state=42), n_estimators=500,
    +    max_samples=100, bootstrap=True, n_jobs=-1, random_state=42)
    +bag_clf.fit(X_train, y_train)
    +y_pred = bag_clf.predict(X_test)
     

    from sklearn.metrics import accuracy_score
    -
    -for clf in (log_clf, rnd_clf, svm_clf, voting_clf):
    -    clf.fit(X_train, y_train)
    -    y_pred = clf.predict(X_test)
    -    print(clf.__class__.__name__, accuracy_score(y_test, y_pred))
    +print(accuracy_score(y_test, y_pred))
     

    -

    log_clf = LogisticRegression(random_state=42)
    -rnd_clf = RandomForestClassifier(random_state=42)
    -svm_clf = SVC(probability=True, random_state=42)
    -
    -voting_clf = VotingClassifier(
    -    estimators=[('lr', log_clf), ('rf', rnd_clf), ('svc', svm_clf)],
    -    voting='soft')
    -voting_clf.fit(X_train, y_train)
    +
    tree_clf = DecisionTreeClassifier(random_state=42)
    +tree_clf.fit(X_train, y_train)
    +y_pred_tree = tree_clf.predict(X_test)
    +print(accuracy_score(y_test, y_pred_tree))
     

    -

    from sklearn.metrics import accuracy_score
    +
    from matplotlib.colors import ListedColormap
     
    -for clf in (log_clf, rnd_clf, svm_clf, voting_clf):
    -    clf.fit(X_train, y_train)
    -    y_pred = clf.predict(X_test)
    -    print(clf.__class__.__name__, accuracy_score(y_test, y_pred))
    +def plot_decision_boundary(clf, X, y, axes=[-1.5, 2.5, -1, 1.5], alpha=0.5, contour=True):
    +    x1s = np.linspace(axes[0], axes[1], 100)
    +    x2s = np.linspace(axes[2], axes[3], 100)
    +    x1, x2 = np.meshgrid(x1s, x2s)
    +    X_new = np.c_[x1.ravel(), x2.ravel()]
    +    y_pred = clf.predict(X_new).reshape(x1.shape)
    +    custom_cmap = ListedColormap(['#fafab0','#9898ff','#a0faa0'])
    +    plt.contourf(x1, x2, y_pred, alpha=0.3, cmap=custom_cmap)
    +    if contour:
    +        custom_cmap2 = ListedColormap(['#7d7d58','#4c4c7f','#507d50'])
    +        plt.contour(x1, x2, y_pred, cmap=custom_cmap2, alpha=0.8)
    +    plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo", alpha=alpha)
    +    plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs", alpha=alpha)
    +    plt.axis(axes)
    +    plt.xlabel(r"$x_1$", fontsize=18)
    +    plt.ylabel(r"$x_2$", fontsize=18, rotation=0)
    +plt.figure(figsize=(11,4))
    +plt.subplot(121)
    +plot_decision_boundary(tree_clf, X, y)
    +plt.title("Decision Tree", fontsize=14)
    +plt.subplot(122)
    +plot_decision_boundary(bag_clf, X, y)
    +plt.title("Decision Trees with Bagging", fontsize=14)
    +plt.show()
     

    @@ -230,7 +231,6 @@ voting_clf.fit(X_train, y_train)

  • 27
  • 28
  • 29
  • -
  • 30
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs027.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs027.html index 0b8137717..154f3758c 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs027.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs027.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -157,63 +155,24 @@ MathJax.Hub.Config({ -

    Bagging examples

    - +

    Then random forests

    -

    from sklearn.ensemble import BaggingClassifier
    -from sklearn.tree import DecisionTreeClassifier
    +
    bag_clf = BaggingClassifier(
    +    DecisionTreeClassifier(splitter="random", max_leaf_nodes=16, random_state=42),
    +    n_estimators=500, max_samples=1.0, bootstrap=True, n_jobs=-1, random_state=42)
    +
    +

    -bag_clf = BaggingClassifier( - DecisionTreeClassifier(random_state=42), n_estimators=500, - max_samples=100, bootstrap=True, n_jobs=-1, random_state=42) -bag_clf.fit(X_train, y_train) + +

    bag_clf.fit(X_train, y_train)
     y_pred = bag_clf.predict(X_test)
    -
    -

    - - -

    from sklearn.metrics import accuracy_score
    -print(accuracy_score(y_test, y_pred))
    -
    -

    - - -

    tree_clf = DecisionTreeClassifier(random_state=42)
    -tree_clf.fit(X_train, y_train)
    -y_pred_tree = tree_clf.predict(X_test)
    -print(accuracy_score(y_test, y_pred_tree))
    -
    -

    - - -

    from matplotlib.colors import ListedColormap
    -
    -def plot_decision_boundary(clf, X, y, axes=[-1.5, 2.5, -1, 1.5], alpha=0.5, contour=True):
    -    x1s = np.linspace(axes[0], axes[1], 100)
    -    x2s = np.linspace(axes[2], axes[3], 100)
    -    x1, x2 = np.meshgrid(x1s, x2s)
    -    X_new = np.c_[x1.ravel(), x2.ravel()]
    -    y_pred = clf.predict(X_new).reshape(x1.shape)
    -    custom_cmap = ListedColormap(['#fafab0','#9898ff','#a0faa0'])
    -    plt.contourf(x1, x2, y_pred, alpha=0.3, cmap=custom_cmap)
    -    if contour:
    -        custom_cmap2 = ListedColormap(['#7d7d58','#4c4c7f','#507d50'])
    -        plt.contour(x1, x2, y_pred, cmap=custom_cmap2, alpha=0.8)
    -    plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo", alpha=alpha)
    -    plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs", alpha=alpha)
    -    plt.axis(axes)
    -    plt.xlabel(r"$x_1$", fontsize=18)
    -    plt.ylabel(r"$x_2$", fontsize=18, rotation=0)
    -plt.figure(figsize=(11,4))
    -plt.subplot(121)
    -plot_decision_boundary(tree_clf, X, y)
    -plt.title("Decision Tree", fontsize=14)
    -plt.subplot(122)
    -plot_decision_boundary(bag_clf, X, y)
    -plt.title("Decision Trees with Bagging", fontsize=14)
    -plt.show()
    +from sklearn.ensemble import RandomForestClassifier
    +rnd_clf = RandomForestClassifier(n_estimators=500, max_leaf_nodes=16, n_jobs=-1, random_state=42)
    +rnd_clf.fit(X_train, y_train)
    +y_pred_rf = rnd_clf.predict(X_test)
    +np.sum(y_pred == y_pred_rf) / len(y_pred) 
     

    @@ -232,7 +191,6 @@ plt.show()

  • 27
  • 28
  • 29
  • -
  • 30
  • »
  • diff --git a/doc/pub/DecisionTrees/html/._DecisionTrees-bs028.html b/doc/pub/DecisionTrees/html/._DecisionTrees-bs028.html index 806ee8294..0988bec6c 100644 --- a/doc/pub/DecisionTrees/html/._DecisionTrees-bs028.html +++ b/doc/pub/DecisionTrees/html/._DecisionTrees-bs028.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -155,28 +153,13 @@ MathJax.Hub.Config({

     

     

     

    - + + +

    Boosting and more

    +More material to come here. -

    Then random forests

    - -

    bag_clf = BaggingClassifier(
    -    DecisionTreeClassifier(splitter="random", max_leaf_nodes=16, random_state=42),
    -    n_estimators=500, max_samples=1.0, bootstrap=True, n_jobs=-1, random_state=42)
    -
    -

    - - -

    bag_clf.fit(X_train, y_train)
    -y_pred = bag_clf.predict(X_test)
    -from sklearn.ensemble import RandomForestClassifier
    -rnd_clf = RandomForestClassifier(n_estimators=500, max_leaf_nodes=16, n_jobs=-1, random_state=42)
    -rnd_clf.fit(X_train, y_train)
    -y_pred_rf = rnd_clf.predict(X_test)
    -np.sum(y_pred == y_pred_rf) / len(y_pred) 
    -
    -

      @@ -192,8 +175,6 @@ np.sum(y_pred =
    • 27
    • 28
    • 29
    • -
    • 30
    • -
    • »
    diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-bs.html b/doc/pub/DecisionTrees/html/DecisionTrees-bs.html index a0cf685f0..a1f2bc91d 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-bs.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-bs.html @@ -52,30 +52,29 @@ Automatically generated HTML file from DocOnce source ('Making a tree', 2, None, '___sec5'), ('Pruning the tree', 2, None, '___sec6'), ('Cost complexity pruning', 2, None, '___sec7'), - ('A schematic procedure', 2, None, '___sec8'), - ('A classification tree', 2, None, '___sec9'), + ('Schematic Regression Procedure', 2, None, '___sec8'), + ('A Classification Tree', 2, None, '___sec9'), ('Growing a classification tree', 2, None, '___sec10'), ('Classification tree, how to split nodes', 2, None, '___sec11'), ('Entropy and the ID3 algorithm', 2, None, '___sec12'), - ('Writing your own code for a classification tree', + ('Cancer Data again now with Decision Trees', 2, None, '___sec13'), - ('Back to moons again', 2, None, '___sec14'), + ('Another example, the moons again', 2, None, '___sec14'), ('Playing around with regions', 2, None, '___sec15'), ('Regression trees', 2, None, '___sec16'), ('Final regressor code', 2, None, '___sec17'), - ('Classification again: The zoo data', 2, None, '___sec18'), - ('Pros and cons of trees, pros', 2, None, '___sec19'), - ('Disadvantages', 2, None, '___sec20'), - ('Bagging', 2, None, '___sec21'), - ('Simple example, head or tail', 2, None, '___sec22'), - ('Random forests', 2, None, '___sec23'), - ('A simple scikit-learn example', 2, None, '___sec24'), - ('Please, not the moons again!', 2, None, '___sec25'), - ('Bagging examples', 2, None, '___sec26'), - ('Then random forests', 2, None, '___sec27'), - ('Boosting and more', 2, None, '___sec28')]} + ('Pros and cons of trees, pros', 2, None, '___sec18'), + ('Disadvantages', 2, None, '___sec19'), + ('Bagging', 2, None, '___sec20'), + ('Simple example, head or tail', 2, None, '___sec21'), + ('Random forests', 2, None, '___sec22'), + ('A simple scikit-learn example', 2, None, '___sec23'), + ('Please, not the moons again!', 2, None, '___sec24'), + ('Bagging examples', 2, None, '___sec25'), + ('Then random forests', 2, None, '___sec26'), + ('Boosting and more', 2, None, '___sec27')]} end of tocinfo --> @@ -121,27 +120,26 @@ MathJax.Hub.Config({
  • Making a tree
  • Pruning the tree
  • Cost complexity pruning
  • -
  • A schematic procedure
  • -
  • A classification tree
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • Growing a classification tree
  • Classification tree, how to split nodes
  • Entropy and the ID3 algorithm
  • -
  • Writing your own code for a classification tree
  • -
  • Back to moons again
  • +
  • Cancer Data again now with Decision Trees
  • +
  • Another example, the moons again
  • Playing around with regions
  • Regression trees
  • Final regressor code
  • -
  • Classification again: The zoo data
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Bagging
  • -
  • Simple example, head or tail
  • -
  • Random forests
  • -
  • A simple scikit-learn example
  • -
  • Please, not the moons again!
  • -
  • Bagging examples
  • -
  • Then random forests
  • -
  • Boosting and more
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Bagging
  • +
  • Simple example, head or tail
  • +
  • Random forests
  • +
  • A simple scikit-learn example
  • +
  • Please, not the moons again!
  • +
  • Bagging examples
  • +
  • Then random forests
  • +
  • Boosting and more
  • @@ -176,7 +174,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

    -

    Oct 24, 2019

    +

    Oct 25, 2019


    @@ -200,7 +198,7 @@ MathJax.Hub.Config({

  • 9
  • 10
  • ...
  • -
  • 30
  • +
  • 29
  • »
  • diff --git a/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html b/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html index 3cd494223..791a5279f 100644 --- a/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html +++ b/doc/pub/DecisionTrees/html/DecisionTrees-reveal.html @@ -148,7 +148,7 @@ MathJax.Hub.Config({
    [2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University

     
    -

    Oct 24, 2019

    +

    Oct 25, 2019


    @@ -315,13 +315,8 @@ plt.show() There are mainly two steps

      -

    1. We split the predictor space (the set of possible values \( x_1,x_2,\dots, x_p \)) into \( J \)
    2. -
    -

    +

  • 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 \).
  • -distinct and non-non-overlapping regions, \( R_1,R_2,\dots,R_J \). - -

    1. 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 \).

    @@ -330,7 +325,7 @@ 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 predic- tive model. The goal is to find boxes \( R_1,\dots,R_J \) +resulting predictive model. The goal is to find boxes \( R_1,\dots,R_J \) that minimize the MSE, given by

     
    $$ @@ -339,8 +334,7 @@ $$

     
    where \( \overline{y}_{R_j} \) is the mean response for the training observations -within the $j$th -box. +within box \( j \). @@ -469,7 +463,7 @@ subtree corresponding to \( \alpha \).

    -

    A schematic procedure

    +

    Schematic Regression Procedure

    @@ -494,7 +488,7 @@ subtree corresponding to \( \alpha \).
    -

    A classification tree

    +

    A Classification Tree

    A classification tree is very similar to a regression tree, except @@ -538,6 +532,8 @@ than is the classification error rate.

    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. @@ -587,105 +583,62 @@ $$

    Entropy and the ID3 algorithm

    -More text to come here. +More text and code to come here.

    -

    Writing your own code for a classification tree

    - +

    Cancer Data again now with Decision Trees

    -

    def entropy(target_col):
    -    """
    -    Calculate the entropy of a dataset.
    -    The only parameter of this function is the target_col parameter which specifies the target column
    -    """
    -    elements,counts = np.unique(target_col,return_counts = True)
    -    entropy = np.sum([(-counts[i]/np.sum(counts))*np.log2(counts[i]/np.sum(counts)) for i in range(len(elements))])
    -    return entropy
    +
    import matplotlib.pyplot as plt
    +import numpy as np
    +from sklearn.model_selection import  train_test_split 
    +from sklearn.datasets import load_breast_cancer
    +from sklearn.svm import SVC
    +from sklearn.linear_model import LogisticRegression
    +from sklearn.tree import DecisionTreeClassifier
     
    -def InfoGain(data,split_attribute_name,target_name="class"):
    -    """
    -    Calculate the information gain of a dataset. This function takes three parameters:
    -    1. data = The dataset for whose feature the IG should be calculated
    -    2. split_attribute_name = the name of the feature for which the information gain should be calculated
    -    3. target_name = the name of the target feature. The default for this example is "class"
    -    """    
    -    #Calculate the entropy of the total dataset
    -    total_entropy = entropy(data[target_name])
    -    
    -    ##Calculate the entropy of the dataset
    -    
    -    #Calculate the values and the corresponding counts for the split attribute 
    -    vals,counts= np.unique(data[split_attribute_name],return_counts=True)
    -    
    -    #Calculate the weighted entropy
    -    Weighted_Entropy = np.sum([(counts[i]/np.sum(counts))*entropy(data.where(data[split_attribute_name]==vals[i]).dropna()[target_name]) for i in range(len(vals))])
    -    
    -    #Calculate the information gain
    -    Information_Gain = total_entropy - Weighted_Entropy
    -    return Information_Gain
    -       
    +# Load the data
    +cancer = load_breast_cancer()
     
    -def ID3(data,originaldata,features,target_attribute_name="class",parent_node_class = None):
    -    #Define the stopping criteria --> If one of this is satisfied, we want to return a leaf node#
    -    
    -    #If all target_values have the same value, return this value
    -    if len(np.unique(data[target_attribute_name])) <= 1:
    -        return np.unique(data[target_attribute_name])[0]
    -    
    -    #If the dataset is empty, return the mode target feature value in the original dataset
    -    elif len(data)==0:
    -        return np.unique(originaldata[target_attribute_name])[np.argmax(np.unique(originaldata[target_attribute_name],return_counts=True)[1])]
    -    
    -    #If the feature space is empty, return the mode target feature value of the direct parent node --> Note that
    -    #the direct parent node is that node which has called the current run of the ID3 algorithm and hence
    -    #the mode target feature value is stored in the parent_node_class variable.
    -    
    -    elif len(features) ==0:
    -        return parent_node_class
    -    
    -    #If none of the above holds true, grow the tree!
    -    
    -    else:
    -        #Set the default value for this node --> The mode target feature value of the current node
    -        parent_node_class = np.unique(data[target_attribute_name])[np.argmax(np.unique(data[target_attribute_name],return_counts=True)[1])]
    -        
    -        #Select the feature which best splits the dataset
    -        item_values = [InfoGain(data,feature,target_attribute_name) for feature in features] #Return the information gain values for the features in the dataset
    -        best_feature_index = np.argmax(item_values)
    -        best_feature = features[best_feature_index]
    -        
    -        #Create the tree structure. The root gets the name of the feature (best_feature) with the maximum information
    -        #gain in the first run
    -        tree = {best_feature:{}}
    -        
    -        
    -        #Remove the feature with the best inforamtion gain from the feature space
    -        features = [i for i in features if i != best_feature]
    -        
    -        #Grow a branch under the root node for each possible value of the root node feature
    -        
    -        for value in np.unique(data[best_feature]):
    -            value = value
    -            #Split the dataset along the value of the feature with the largest information gain and therwith create sub_datasets
    -            sub_data = data.where(data[best_feature] == value).dropna()
    -            
    -            #Call the ID3 algorithm for each of those sub_datasets with the new parameters --> Here the recursion comes in!
    -            subtree = ID3(sub_data,dataset,features,target_attribute_name,parent_node_class)
    -            
    -            #Add the sub tree, grown from the sub_dataset to the tree under the root node
    -            tree[best_feature][value] = subtree
    -            
    -        return(tree)    
    +X_train, X_test, y_train, y_test = train_test_split(cancer.data,cancer.target,random_state=0)
    +print(X_train.shape)
    +print(X_test.shape)
    +# Logistic Regression
    +logreg = LogisticRegression(solver='lbfgs')
    +logreg.fit(X_train, y_train)
    +print("Test set accuracy with Logistic Regression: {:.2f}".format(logreg.score(X_test,y_test)))
    +# Support vector machine
    +svm = SVC(gamma='auto', C=100)
    +svm.fit(X_train, y_train)
    +print("Test set accuracy with SVM: {:.2f}".format(svm.score(X_test,y_test)))
    +# Decision Trees
    +deep_tree_clf = DecisionTreeClassifier(max_depth=None)
    +deep_tree_clf.fit(X_train, y_train)
    +print("Test set accuracy with Decision Trees: {:.2f}".format(deep_tree_clf.score(X_test,y_test)))
    +#now scale the data
    +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)
    +# Logistic Regression
    +logreg.fit(X_train_scaled, y_train)
    +print("Test set accuracy Logistic Regression with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
    +# Support Vector Machine
    +svm.fit(X_train_scaled, y_train)
    +print("Test set accuracy SVM with scaled data: {:.2f}".format(logreg.score(X_test_scaled,y_test)))
    +# Decision Trees
    +deep_tree_clf.fit(X_train_scaled, y_train)
    +print("Test set accuracy with Decision Trees and scaled data: {:.2f}".format(deep_tree_clf.score(X_test_scaled,y_test)))
     
    -

    Back to moons again

    +

    Another example, the moons again

    @@ -889,36 +842,7 @@ plt.show()

    -

    Classification again: The zoo data

    -

    - - -

    import pandas as pd
    -import numpy as np
    -from pprint import pprint
    -from sklearn.tree import DecisionTreeClassifier
    -
    -#Import the dataset 
    -dataset = pd.read_csv('data/zoo.csv')
    -#We drop the animal names since this is not a good feature to split the data on
    -#dataset=dataset.drop('animal_name',axis=1)
    -#Split the data into a training and a testing set
    -train_features = dataset.iloc[:80,:-1]
    -test_features = dataset.iloc[80:,:-1]
    -train_targets = dataset.iloc[:80,-1]
    -test_targets = dataset.iloc[80:,-1]
    -#Train the model
    -tree = DecisionTreeClassifier(criterion = 'entropy').fit(train_features,train_targets)
    -#Predict the classes of new, unseen data
    -prediction = tree.predict(test_features)
    -#Check the accuracy
    -print("The prediction accuracy is: ",tree.score(test_features,test_targets)*100,"%")
    -
    -
    - - -
    -

    Pros and cons of trees, pros

    +

    Pros and cons of trees, pros