From e541dbfe0815b489efc8c4337dc4475429c080e9 Mon Sep 17 00:00:00 2001 From: Morten Hjorth-Jensen Date: Thu, 4 Nov 2021 08:29:21 +0100 Subject: [PATCH] update week 44 --- doc/pub/week44/html/._week44-bs000.html | 124 ++++---- doc/pub/week44/html/._week44-bs001.html | 124 ++++---- doc/pub/week44/html/._week44-bs002.html | 135 ++++----- doc/pub/week44/html/._week44-bs003.html | 154 +++++----- doc/pub/week44/html/._week44-bs004.html | 158 ++++++----- doc/pub/week44/html/._week44-bs005.html | 141 ++++----- doc/pub/week44/html/._week44-bs006.html | 149 +++++----- doc/pub/week44/html/._week44-bs007.html | 156 +++++----- doc/pub/week44/html/._week44-bs008.html | 154 +++++----- doc/pub/week44/html/._week44-bs009.html | 154 +++++----- doc/pub/week44/html/._week44-bs010.html | 144 +++++----- doc/pub/week44/html/._week44-bs011.html | 139 ++++----- doc/pub/week44/html/._week44-bs012.html | 136 ++++----- doc/pub/week44/html/._week44-bs013.html | 250 +++++----------- doc/pub/week44/html/._week44-bs014.html | 241 ++++++++++------ doc/pub/week44/html/._week44-bs015.html | 184 ++++++------ doc/pub/week44/html/._week44-bs016.html | 191 ++++++------- doc/pub/week44/html/._week44-bs017.html | 231 ++++++--------- doc/pub/week44/html/._week44-bs018.html | 269 ++++++++++++------ doc/pub/week44/html/._week44-bs019.html | 155 +++++----- doc/pub/week44/html/._week44-bs020.html | 138 +++++---- doc/pub/week44/html/._week44-bs021.html | 128 +++++---- doc/pub/week44/html/._week44-bs022.html | 134 +++++---- doc/pub/week44/html/._week44-bs023.html | 142 +++++----- doc/pub/week44/html/._week44-bs024.html | 146 +++++----- doc/pub/week44/html/._week44-bs025.html | 244 +++++----------- doc/pub/week44/html/._week44-bs026.html | 251 ++++++++++------ doc/pub/week44/html/._week44-bs027.html | 153 +++++----- doc/pub/week44/html/._week44-bs028.html | 178 +++++------- doc/pub/week44/html/._week44-bs029.html | 180 +++++++----- doc/pub/week44/html/._week44-bs030.html | 162 +++++------ doc/pub/week44/html/._week44-bs031.html | 167 ++++++----- doc/pub/week44/html/._week44-bs032.html | 157 +++++----- doc/pub/week44/html/._week44-bs033.html | 155 +++++----- doc/pub/week44/html/._week44-bs034.html | 178 ++++++------ doc/pub/week44/html/._week44-bs035.html | 210 +++++++------- doc/pub/week44/html/._week44-bs036.html | 155 +++++----- doc/pub/week44/html/._week44-bs037.html | 160 ++++++----- doc/pub/week44/html/._week44-bs038.html | 143 +++++----- doc/pub/week44/html/._week44-bs039.html | 168 ++++++----- doc/pub/week44/html/._week44-bs040.html | 156 +++++----- doc/pub/week44/html/._week44-bs041.html | 158 ++++++----- doc/pub/week44/html/._week44-bs042.html | 182 ++++++------ doc/pub/week44/html/._week44-bs043.html | 251 +++++++--------- doc/pub/week44/html/._week44-bs044.html | 257 ++++++++--------- doc/pub/week44/html/._week44-bs045.html | 233 +++++++++------ doc/pub/week44/html/._week44-bs046.html | 211 ++++++-------- doc/pub/week44/html/._week44-bs047.html | 221 +++++++-------- doc/pub/week44/html/._week44-bs048.html | 196 ++++++++----- doc/pub/week44/html/._week44-bs049.html | 173 ++++++----- doc/pub/week44/html/._week44-bs050.html | 200 +++++-------- doc/pub/week44/html/._week44-bs051.html | 242 +++++++++++----- doc/pub/week44/html/._week44-bs052.html | 145 +++++----- doc/pub/week44/html/._week44-bs053.html | 156 +++++----- doc/pub/week44/html/._week44-bs054.html | 150 +++++----- doc/pub/week44/html/._week44-bs055.html | 143 +++++----- doc/pub/week44/html/._week44-bs056.html | 155 +++++----- doc/pub/week44/html/._week44-bs057.html | 180 ++++++------ doc/pub/week44/html/._week44-bs058.html | 181 +++++------- doc/pub/week44/html/._week44-bs059.html | 204 +++++-------- doc/pub/week44/html/._week44-bs060.html | 274 +++++++++--------- doc/pub/week44/html/week44-bs.html | 124 ++++---- doc/pub/week44/html/week44-reveal.html | 13 + doc/pub/week44/html/week44-solarized.html | 13 + doc/pub/week44/html/week44.html | 13 + doc/pub/week44/ipynb/ipynb-week44-src.tar.gz | Bin 294283 -> 294283 bytes doc/pub/week44/ipynb/week44.ipynb | 284 ++++++++++--------- doc/src/week44/week44.do.txt | 12 + 68 files changed, 5678 insertions(+), 5587 deletions(-) diff --git a/doc/pub/week44/html/._week44-bs000.html b/doc/pub/week44/html/._week44-bs000.html index c4db98304..a503062e6 100644 --- a/doc/pub/week44/html/._week44-bs000.html +++ b/doc/pub/week44/html/._week44-bs000.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -363,7 +365,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs001.html b/doc/pub/week44/html/._week44-bs001.html index 1dbf28a07..fcaff62e0 100644 --- a/doc/pub/week44/html/._week44-bs001.html +++ b/doc/pub/week44/html/._week44-bs001.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -365,7 +367,7 @@ MathJax.Hub.Config({
  • 10
  • 11
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs002.html b/doc/pub/week44/html/._week44-bs002.html index 986eee8c8..6114410dd 100644 --- a/doc/pub/week44/html/._week44-bs002.html +++ b/doc/pub/week44/html/._week44-bs002.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,10 +322,15 @@ MathJax.Hub.Config({

     

     

     

    -

    Thursday, Principal Component Analysis

    +

    Digression First

    -

    For the principal component analysis, -see slides from week 43, in particular from slide 28 and forward +

    For those of you interested in the fast growing areas of applications of Machine Learning, this article about Applications and techniques for fast machine learning in science may be interesting.

    + +

    It has several interesting perspectives and highly interesting +applications that link scientific discoveries with efficient software +and hardware. The emphasis is onintegrating power Machine Learning +methods into the real-time experimental data processing loop to +accelerate scientific discovery.

    @@ -343,7 +350,7 @@ see slides from 11

  • 12
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs003.html b/doc/pub/week44/html/._week44-bs003.html index a6a8a209c..072a49115 100644 --- a/doc/pub/week44/html/._week44-bs003.html +++ b/doc/pub/week44/html/._week44-bs003.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,34 +322,10 @@ MathJax.Hub.Config({

     

     

     

    -

    A kind of Bird's view on PCA

    +

    Thursday, Principal Component Analysis

    -Why do we maximize variance during Principal Component Analysis? - -

    Variance is a measure of the variability of the data you -have. Potentially the number of components is infinite, so you want to "squeeze" the most -information in each component of the finite set you build. -

    - -

    If, to exaggerate, you were to select a single principal component, -you would want it to account for the most variability possible: hence -the search for maximum variance, so that the one component collects -the most "uniqueness" from the data set. -

    - -

    Maximizing the component vector variances is the same as maximizing -the 'uniqueness' of those vectors. The vectors are as distant -from each other as possible (orthogonal to each other). -

    - -

    Take for example a situation where you have 2 lines that are -orthogonal in a 3D space. You can capture the environment much more -completely with those orthogonal lines than 2 lines that are parallel -(or nearly parallel). When applied to very high dimensional states -using very few vectors, this becomes a much more important -relationship among the vectors to maintain. In a linear algebra sense -you want independent rows to be produced by PCA, otherwise some of -those rows will be redundant. +

    For the principal component analysis, +see slides from week 43, in particular from slide 28 and forward

    @@ -368,7 +346,7 @@ those rows will be redundant.

  • 12
  • 13
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs004.html b/doc/pub/week44/html/._week44-bs004.html index f0645d8c9..b6d7730aa 100644 --- a/doc/pub/week44/html/._week44-bs004.html +++ b/doc/pub/week44/html/._week44-bs004.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,18 +322,34 @@ MathJax.Hub.Config({

     

     

     

    -

    Thursday: Clustering and Unsupervised Learning

    +

    A kind of Bird's view on PCA

    -

    In general terms cluster analysis, or clustering, is the task of grouping a -data-set into different distinct categories based on some measure of equality of -the data. This measure is often referred to as a metric or similarity -measure in the literature (note: sometimes we deal with a dissimilarity -measure instead). Usually, these metrics are formulated as some kind of -distance function between points in a high-dimensional space. +Why do we maximize variance during Principal Component Analysis? + +

    Variance is a measure of the variability of the data you +have. Potentially the number of components is infinite, so you want to "squeeze" the most +information in each component of the finite set you build.

    -

    The simplest, and also the most -common is the Euclidean distance. +

    If, to exaggerate, you were to select a single principal component, +you would want it to account for the most variability possible: hence +the search for maximum variance, so that the one component collects +the most "uniqueness" from the data set. +

    + +

    Maximizing the component vector variances is the same as maximizing +the 'uniqueness' of those vectors. The vectors are as distant +from each other as possible (orthogonal to each other). +

    + +

    Take for example a situation where you have 2 lines that are +orthogonal in a 3D space. You can capture the environment much more +completely with those orthogonal lines than 2 lines that are parallel +(or nearly parallel). When applied to very high dimensional states +using very few vectors, this becomes a much more important +relationship among the vectors to maintain. In a linear algebra sense +you want independent rows to be produced by PCA, otherwise some of +those rows will be redundant.

    @@ -353,7 +371,7 @@ common is the Euclidean distance.

  • 13
  • 14
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs005.html b/doc/pub/week44/html/._week44-bs005.html index 4133a4426..6cb747086 100644 --- a/doc/pub/week44/html/._week44-bs005.html +++ b/doc/pub/week44/html/._week44-bs005.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,13 +322,18 @@ MathJax.Hub.Config({

     

     

     

    -

    Basic Idea of the \( k \)-means Clustering Algorithm

    +

    Thursday: Clustering and Unsupervised Learning

    -

    The simplest of all clustering algorithms is the k-means algorithm -, sometimes also referred to as Lloyds algorithm. It is the simplest and also -the most common. From its simplicity it obtains both strengths and weaknesses. -These will be discussed in more detail later. The \( k \)-means algorithm is a -centroid based clustering algorithm. +

    In general terms cluster analysis, or clustering, is the task of grouping a +data-set into different distinct categories based on some measure of equality of +the data. This measure is often referred to as a metric or similarity +measure in the literature (note: sometimes we deal with a dissimilarity +measure instead). Usually, these metrics are formulated as some kind of +distance function between points in a high-dimensional space. +

    + +

    The simplest, and also the most +common is the Euclidean distance.

    @@ -349,7 +356,7 @@ These will be discussed in more detail later. The \( k \)-means algorithm is a

  • 14
  • 15
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs006.html b/doc/pub/week44/html/._week44-bs006.html index 9cc12fb40..69824ad1c 100644 --- a/doc/pub/week44/html/._week44-bs006.html +++ b/doc/pub/week44/html/._week44-bs006.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,28 +322,15 @@ MathJax.Hub.Config({

     

     

     

    -

    The \( k \)-means Algorithm

    +

    Basic Idea of the \( k \)-means Clustering Algorithm

    -

    Assume, we are given \( n \) data points and we wish to split the data into \( K < n \) -different categories, or clusters. We label each cluster by an integer +

    The simplest of all clustering algorithms is the k-means algorithm +, sometimes also referred to as Lloyds algorithm. It is the simplest and also +the most common. From its simplicity it obtains both strengths and weaknesses. +These will be discussed in more detail later. The \( k \)-means algorithm is a +centroid based clustering algorithm.

    -$$ k\in\{1, \cdots, K \}. -$$ - -

    In the basic k-means algorithm each point is assigned to only -one cluster \( k \), and these assignments are non-injective i.e. many-to-one. We -can think of these mappings as an encoder \( k = C(i) \), which assigns the \( i \)-th -data-point \( \bf x_i \) to the \( k \)-th cluster. -

    - -

    \( k \)-means algorithm in words:

    -
      -
    1. We start with guesses / random initializations of our \( k \) cluster centers/centroids
    2. -
    3. For each centroid the points that are most similar are identified
    4. -
    5. Then we move / replace each centroid with a coordinate average of all the points that were assigned to that centroid.
    6. -
    7. Iterate 2-3 until the centroids no longer move (to some tolerance)
    8. -

    diff --git a/doc/pub/week44/html/._week44-bs007.html b/doc/pub/week44/html/._week44-bs007.html index 3c3233dc0..505fc711f 100644 --- a/doc/pub/week44/html/._week44-bs007.html +++ b/doc/pub/week44/html/._week44-bs007.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,26 +322,28 @@ MathJax.Hub.Config({

     

     

     

    -

    Basic Math of the \( k \)-means Algorithm

    +

    The \( k \)-means Algorithm

    -

    We assume we have \( n \) data-points

    -$$ -\begin{equation}\tag{1} - \boldsymbol{x_i} = \{x_{i, 1}, \cdots, x_{i, p}\}\in\mathbb{R}^p. -\end{equation} -$$ - -

    which we wish to group into \( K < n \) clusters. For our dissimilarity measure we -use the squared Euclidean distance +

    Assume, we are given \( n \) data points and we wish to split the data into \( K < n \) +different categories, or clusters. We label each cluster by an integer

    -$$ -\begin{equation}\tag{2} - d(\boldsymbol{x_i}, \boldsymbol{x_i'}) = \sum_{j=1}^p(x_{ij} - x_{i'j})^2 - = ||\boldsymbol{x_i} - \boldsymbol{x_{i'}}||^2 -\end{equation} + +$$ k\in\{1, \cdots, K \}. $$ +

    In the basic k-means algorithm each point is assigned to only +one cluster \( k \), and these assignments are non-injective i.e. many-to-one. We +can think of these mappings as an encoder \( k = C(i) \), which assigns the \( i \)-th +data-point \( \bf x_i \) to the \( k \)-th cluster. +

    +

    \( k \)-means algorithm in words:

    +
      +
    1. We start with guesses / random initializations of our \( k \) cluster centers/centroids
    2. +
    3. For each centroid the points that are most similar are identified
    4. +
    5. Then we move / replace each centroid with a coordinate average of all the points that were assigned to that centroid.
    6. +
    7. Iterate 2-3 until the centroids no longer move (to some tolerance)
    8. +

    diff --git a/doc/pub/week44/html/._week44-bs008.html b/doc/pub/week44/html/._week44-bs008.html index b99a07e12..98b6c480b 100644 --- a/doc/pub/week44/html/._week44-bs008.html +++ b/doc/pub/week44/html/._week44-bs008.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,29 +322,25 @@ MathJax.Hub.Config({

     

     

     

    -

    Within Cluster Point Scatter

    +

    Basic Math of the \( k \)-means Algorithm

    -

    We define the so called within-cluster point scatter which gives us a -measure of how close each data point assigned to the same cluster tends to be to -the all the others. -

    +

    We assume we have \( n \) data-points

    $$ -\begin{equation}\tag{3} - W(C) = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k} - \sum_{C(i')=k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) = - \sum_{k=1}^KN_k\sum_{C(i)=k}||\boldsymbol{x_i} - \boldsymbol{\overline{x_k}}||^2 +\begin{equation}\tag{1} + \boldsymbol{x_i} = \{x_{i, 1}, \cdots, x_{i, p}\}\in\mathbb{R}^p. \end{equation} $$ -

    where \( \boldsymbol{\overline{x_k}} \) is the mean vector associated with the \( k \)-th -cluster, and \( N_k = \sum_{i=1}^nI(C(i) = k) \), where the \( I() \) notation is -similar to the Kronecker delta (Commonly used in statistics, it just means that -when \( i = k \) we have the encoder \( C(i) \)). In other words, the within-cluster -scatter measures the compactness of each cluster with respect to the data points -assigned to each cluster. This is the quantity that the \( k \)-means algorithm aims -to minimize. We refer to this quantity \( W(C) \) as the within cluster scatter -because of its relation to the total scatter. +

    which we wish to group into \( K < n \) clusters. For our dissimilarity measure we +use the squared Euclidean distance

    +$$ +\begin{equation}\tag{2} + d(\boldsymbol{x_i}, \boldsymbol{x_i'}) = \sum_{j=1}^p(x_{ij} - x_{i'j})^2 + = ||\boldsymbol{x_i} - \boldsymbol{x_{i'}}||^2 +\end{equation} +$$ +

    @@ -367,7 +365,7 @@ because of its relation to the total scatter.

  • 17
  • 18
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs009.html b/doc/pub/week44/html/._week44-bs009.html index 3564f06b7..faea9cbf4 100644 --- a/doc/pub/week44/html/._week44-bs009.html +++ b/doc/pub/week44/html/._week44-bs009.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,24 +322,28 @@ MathJax.Hub.Config({

     

     

     

    -

    More Details

    +

    Within Cluster Point Scatter

    -

    We have

    +

    We define the so called within-cluster point scatter which gives us a +measure of how close each data point assigned to the same cluster tends to be to +the all the others. +

    $$ -\begin{equation}\tag{4} - T = W(C) + B(C) = \frac{1}{2}\sum_{i=1}^n - \sum_{i'=1}^nd(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) - = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k} - \Big(\sum_{C(i') = k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) - + \sum_{C(i')\neq k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})\Big). +\begin{equation}\tag{3} + W(C) = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k} + \sum_{C(i')=k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) = + \sum_{k=1}^KN_k\sum_{C(i)=k}||\boldsymbol{x_i} - \boldsymbol{\overline{x_k}}||^2 \end{equation} $$ -

    This is a quantity that is conserved throughout the \( k \)-means algorithm. It can -be thought of as the total amount of information in the data, and it is composed -of the aforementioned within-cluster scatter and the between-cluster scatter -\( B(C) \). In methods such as principle component analysis the total scatter is not -conserved. +

    where \( \boldsymbol{\overline{x_k}} \) is the mean vector associated with the \( k \)-th +cluster, and \( N_k = \sum_{i=1}^nI(C(i) = k) \), where the \( I() \) notation is +similar to the Kronecker delta (Commonly used in statistics, it just means that +when \( i = k \) we have the encoder \( C(i) \)). In other words, the within-cluster +scatter measures the compactness of each cluster with respect to the data points +assigned to each cluster. This is the quantity that the \( k \)-means algorithm aims +to minimize. We refer to this quantity \( W(C) \) as the within cluster scatter +because of its relation to the total scatter.

    @@ -364,7 +370,7 @@ conserved.

  • 18
  • 19
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs010.html b/doc/pub/week44/html/._week44-bs010.html index fcd6dada0..7dca89891 100644 --- a/doc/pub/week44/html/._week44-bs010.html +++ b/doc/pub/week44/html/._week44-bs010.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,15 +322,25 @@ MathJax.Hub.Config({

     

     

     

    -

    Total Cluster Variance

    -

    Given a cluster mean \( \boldsymbol{m_k} \) we define the total cluster variance

    +

    More Details

    + +

    We have

    $$ -\begin{equation}\tag{5} - \min_{C, \{\boldsymbol{m_k}\}_1^K}\sum_{k=1}^KN_k\sum||\boldsymbol{x_i} - \boldsymbol{m_k}||^2 +\begin{equation}\tag{4} + T = W(C) + B(C) = \frac{1}{2}\sum_{i=1}^n + \sum_{i'=1}^nd(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) + = \frac{1}{2}\sum_{k=1}^K\sum_{C(i)=k} + \Big(\sum_{C(i') = k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}}) + + \sum_{C(i')\neq k}d(\boldsymbol{x_i}, \boldsymbol{x_{i'}})\Big). \end{equation} $$ -

    Now we have all the pieces necessary to formally revisit the \( k \)-means algorithm.

    +

    This is a quantity that is conserved throughout the \( k \)-means algorithm. It can +be thought of as the total amount of information in the data, and it is composed +of the aforementioned within-cluster scatter and the between-cluster scatter +\( B(C) \). In methods such as principle component analysis the total scatter is not +conserved. +

    @@ -355,7 +367,7 @@ $$

  • 19
  • 20
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs011.html b/doc/pub/week44/html/._week44-bs011.html index 3d5c4422a..417bab534 100644 --- a/doc/pub/week44/html/._week44-bs011.html +++ b/doc/pub/week44/html/._week44-bs011.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,15 +322,16 @@ MathJax.Hub.Config({

     

     

     

    -

    The \( k \)-means Clustering Algorithm

    +

    Total Cluster Variance

    +

    Given a cluster mean \( \boldsymbol{m_k} \) we define the total cluster variance

    +$$ +\begin{equation}\tag{5} + \min_{C, \{\boldsymbol{m_k}\}_1^K}\sum_{k=1}^KN_k\sum||\boldsymbol{x_i} - \boldsymbol{m_k}||^2 +\end{equation} +$$ -

    The \( k \)-means clustering algorithm goes as follows

    +

    Now we have all the pieces necessary to formally revisit the \( k \)-means algorithm.

    -
      -
    1. For a given cluster assignment \( C \), and \( k \) cluster means \( \left\{m_1, \cdots, m_k\right\} \). We minimize the total cluster variance with respect to the cluster means \( \{m_k\} \) yielding the means of the currently assigned clusters.
    2. -
    3. Given a current set of \( k \) means \( \{m_k\} \) the total cluster variance is minimized by assigning each observation to the closest (current) cluster mean. That is $$C(i) = \underset{1\leq k\leq K}{\mathrm{argmin}} ||\boldsymbol{x_i} - \boldsymbol{m_k}||^2$$
    4. -
    5. Steps 1 and 2 are repeated until the assignments do not change.
    6. -

    diff --git a/doc/pub/week44/html/._week44-bs012.html b/doc/pub/week44/html/._week44-bs012.html index d2baa43f3..3ab23bf81 100644 --- a/doc/pub/week44/html/._week44-bs012.html +++ b/doc/pub/week44/html/._week44-bs012.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,14 +322,14 @@ MathJax.Hub.Config({

     

     

     

    -

    Summarizing

    +

    The \( k \)-means Clustering Algorithm

    + +

    The \( k \)-means clustering algorithm goes as follows

      -
    1. Before we start we specify a number \( k \) which is the number of clusters we want to try to separate our data into.
    2. -
    3. We initially choose \( k \) random data points in our data as our initial centroids, or means (this is where the name comes from).
    4. -
    5. Assign each data point to their closest centroid, based on the squared Euclidean distance.
    6. -
    7. For each of the \( k \) cluster we update the centroid by calculating new mean values for all the data points in the cluster.
    8. -
    9. Iteratively minimize the within cluster scatter by performing steps (3, 4) until the new assignments stop changing (can be to some tolerance) or until a maximum number of iterations have passed.
    10. +
    11. For a given cluster assignment \( C \), and \( k \) cluster means \( \left\{m_1, \cdots, m_k\right\} \). We minimize the total cluster variance with respect to the cluster means \( \{m_k\} \) yielding the means of the currently assigned clusters.
    12. +
    13. Given a current set of \( k \) means \( \{m_k\} \) the total cluster variance is minimized by assigning each observation to the closest (current) cluster mean. That is $$C(i) = \underset{1\leq k\leq K}{\mathrm{argmin}} ||\boldsymbol{x_i} - \boldsymbol{m_k}||^2$$
    14. +
    15. Steps 1 and 2 are repeated until the assignments do not change.

    @@ -354,7 +356,7 @@ MathJax.Hub.Config({

  • 21
  • 22
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs013.html b/doc/pub/week44/html/._week44-bs013.html index f61efc141..5b1fc6b81 100644 --- a/doc/pub/week44/html/._week44-bs013.html +++ b/doc/pub/week44/html/._week44-bs013.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,125 +322,15 @@ MathJax.Hub.Config({

     

     

     

    -

    Writing our own Code, the Data Set

    - -

    Let us now program the most basic version of the algorithm using nothing but -Python with numpy arrays. This code is kept intentionally simple to gradually -progress our understanding. There is no vectorization of any kind, and even most -helper functions are not utilized. -

    - -

    We need first a dataset to do our cluster analysis on. In our case -this is a plain vanilla data set using random numbers using a -Gaussian distribution. -

    - - - -
    -
    -
    -
    -
    -
    import time
    -import numpy as np
    -import tensorflow as tf
    -from matplotlib import image
    -import matplotlib.pyplot as plt
    -from sklearn.cluster import KMeans
    -from IPython.display import display
    -
    -np.random.seed(2021)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -

    Next we define functions, for ease of use later, to generate Gaussians and to -set up our toy data set. -

    - - -
    -
    -
    -
    -
    -
    def gaussian_points(dim=2, n_points=1000, mean_vector=np.array([0, 0]),
    -                    sample_variance=1):
    -    """
    -    Very simple custom function to generate gaussian distributed point clusters
    -    with variable dimension, number of points, means in each direction
    -    (must match dim) and sample variance.
    -
    -    Inputs:
    -        dim (int)
    -        n_points (int)
    -        mean_vector (np.array) (where index 0 is x, index 1 is y etc.)
    -        sample_variance (float)
    -
    -    Returns:
    -        data (np.array): with dimensions (dim x n_points)
    -    """
    -
    -    mean_matrix = np.zeros(dim) + mean_vector
    -    covariance_matrix = np.eye(dim) * sample_variance
    -    data = np.random.multivariate_normal(mean_matrix, covariance_matrix,
    -                                    n_points)
    -    return data
    -
    -
    -
    -def generate_simple_clustering_dataset(dim=2, n_points=1000, plotting=True,
    -                                    return_data=True):
    -    """
    -    Toy model to illustrate k-means clustering
    -    """
    -
    -    data1 = gaussian_points(mean_vector=np.array([5, 5]))
    -    data2 = gaussian_points()
    -    data3 = gaussian_points(mean_vector=np.array([1, 4.5]))
    -    data4 = gaussian_points(mean_vector=np.array([5, 1]))
    -    data = np.concatenate((data1, data2, data3, data4), axis=0)
    -
    -    if plotting:
    -        fig, ax = plt.subplots()
    -        ax.scatter(data[:, 0], data[:, 1], alpha=0.2)
    -        ax.set_title('Toy Model Dataset')
    -        plt.show()
    -
    -
    -    if return_data:
    -        return data
    -
    -
    -data = generate_simple_clustering_dataset()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - +

    Summarizing

    +
      +
    1. Before we start we specify a number \( k \) which is the number of clusters we want to try to separate our data into.
    2. +
    3. We initially choose \( k \) random data points in our data as our initial centroids, or means (this is where the name comes from).
    4. +
    5. Assign each data point to their closest centroid, based on the squared Euclidean distance.
    6. +
    7. For each of the \( k \) cluster we update the centroid by calculating new mean values for all the data points in the cluster.
    8. +
    9. Iteratively minimize the within cluster scatter by performing steps (3, 4) until the new assignments stop changing (can be to some tolerance) or until a maximum number of iterations have passed.
    10. +

    diff --git a/doc/pub/week44/html/._week44-bs014.html b/doc/pub/week44/html/._week44-bs014.html index c1cf7b15d..08ec05d41 100644 --- a/doc/pub/week44/html/._week44-bs014.html +++ b/doc/pub/week44/html/._week44-bs014.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,10 +322,17 @@ MathJax.Hub.Config({

     

     

     

    -

    Implementing the \( k \)-means Algorithm

    +

    Writing our own Code, the Data Set

    -

    With the above dataset we start -implementing the \( k \)-means algorithm. +

    Let us now program the most basic version of the algorithm using nothing but +Python with numpy arrays. This code is kept intentionally simple to gradually +progress our understanding. There is no vectorization of any kind, and even most +helper functions are not utilized. +

    + +

    We need first a dataset to do our cluster analysis on. In our case +this is a plain vanilla data set using random numbers using a +Gaussian distribution.

    @@ -333,39 +342,89 @@ implementing the \( k \)-means algorithm.
    -
    n_samples, dimensions = data.shape
    -n_clusters = 4
    +  
    import time
    +import numpy as np
    +import tensorflow as tf
    +from matplotlib import image
    +import matplotlib.pyplot as plt
    +from sklearn.cluster import KMeans
    +from IPython.display import display
     
    -# we randomly initialize our centroids
     np.random.seed(2021)
    -centroids = data[np.random.choice(n_samples, n_clusters, replace=False), :]
    -distances = np.zeros((n_samples, n_clusters))
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    +
    +
    + -# first we need to calculate the distance to each centroid from our data -for k in range(n_clusters): - for n in range(n_samples): - dist = 0 - for d in range(dimensions): - dist += np.abs(data[n, d] - centroids[k, d])**2 - distances[n, k] = dist +

    Next we define functions, for ease of use later, to generate Gaussians and to +set up our toy data set. +

    -# we initialize an array to keep track of to which cluster each point belongs -# the way we set it up here the index tracks which point and the value which -# cluster the point belongs to -cluster_labels = np.zeros(n_samples, dtype='int') + +
    +
    +
    +
    +
    +
    def gaussian_points(dim=2, n_points=1000, mean_vector=np.array([0, 0]),
    +                    sample_variance=1):
    +    """
    +    Very simple custom function to generate gaussian distributed point clusters
    +    with variable dimension, number of points, means in each direction
    +    (must match dim) and sample variance.
     
    -# next we loop through our samples and for every point assign it to the cluster
    -# to which it has the smallest distance to
    -for n in range(n_samples):
    -    # tracking variables (all of this is basically just an argmin)
    -    smallest = 1e10
    -    smallest_row_index = 1e10
    -    for k in range(n_clusters):
    -        if distances[n, k] < smallest:
    -            smallest = distances[n, k]
    -            smallest_row_index = k
    +    Inputs:
    +        dim (int)
    +        n_points (int)
    +        mean_vector (np.array) (where index 0 is x, index 1 is y etc.)
    +        sample_variance (float)
     
    -    cluster_labels[n] = smallest_row_index
    +    Returns:
    +        data (np.array): with dimensions (dim x n_points)
    +    """
    +
    +    mean_matrix = np.zeros(dim) + mean_vector
    +    covariance_matrix = np.eye(dim) * sample_variance
    +    data = np.random.multivariate_normal(mean_matrix, covariance_matrix,
    +                                    n_points)
    +    return data
    +
    +
    +
    +def generate_simple_clustering_dataset(dim=2, n_points=1000, plotting=True,
    +                                    return_data=True):
    +    """
    +    Toy model to illustrate k-means clustering
    +    """
    +
    +    data1 = gaussian_points(mean_vector=np.array([5, 5]))
    +    data2 = gaussian_points()
    +    data3 = gaussian_points(mean_vector=np.array([1, 4.5]))
    +    data4 = gaussian_points(mean_vector=np.array([5, 1]))
    +    data = np.concatenate((data1, data2, data3, data4), axis=0)
    +
    +    if plotting:
    +        fig, ax = plt.subplots()
    +        ax.scatter(data[:, 0], data[:, 1], alpha=0.2)
    +        ax.set_title('Toy Model Dataset')
    +        plt.show()
    +
    +
    +    if return_data:
    +        return data
    +
    +
    +data = generate_simple_clustering_dataset()
     
    @@ -407,7 +466,7 @@ cluster_labels = np23
  • 24
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs015.html b/doc/pub/week44/html/._week44-bs015.html index 6cff8be97..8237638d3 100644 --- a/doc/pub/week44/html/._week44-bs015.html +++ b/doc/pub/week44/html/._week44-bs015.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,12 @@ MathJax.Hub.Config({

     

     

     

    -

    Plotting

    +

    Implementing the \( k \)-means Algorithm

    + +

    With the above dataset we start +implementing the \( k \)-means algorithm. +

    +
    @@ -328,19 +335,39 @@ MathJax.Hub.Config({
    -
    fig = plt.figure()
    -ax = fig.add_subplot()
    -unique_cluster_labels = np.unique(cluster_labels)
    -for i in unique_cluster_labels:
    -    ax.scatter(data[cluster_labels == i, 0],
    -               data[cluster_labels == i, 1],
    -               label = i,
    -               alpha = 0.2)
    -    ax.scatter(centroids[:, 0], centroids[:, 1], c='black')
    +  
    n_samples, dimensions = data.shape
    +n_clusters = 4
     
    -ax.set_title("First Grouping of Points to Centroids")
    +# we randomly initialize our centroids
    +np.random.seed(2021)
    +centroids = data[np.random.choice(n_samples, n_clusters, replace=False), :]
    +distances = np.zeros((n_samples, n_clusters))
     
    -plt.show()
    +# first we need to calculate the distance to each centroid from our data
    +for k in range(n_clusters):
    +    for n in range(n_samples):
    +        dist = 0
    +        for d in range(dimensions):
    +            dist += np.abs(data[n, d] - centroids[k, d])**2
    +            distances[n, k] = dist
    +
    +# we initialize an array to keep track of to which cluster each point belongs
    +# the way we set it up here the index tracks which point and the value which
    +# cluster the point belongs to
    +cluster_labels = np.zeros(n_samples, dtype='int')
    +
    +# next we loop through our samples and for every point assign it to the cluster
    +# to which it has the smallest distance to
    +for n in range(n_samples):
    +    # tracking variables (all of this is basically just an argmin)
    +    smallest = 1e10
    +    smallest_row_index = 1e10
    +    for k in range(n_clusters):
    +        if distances[n, k] < smallest:
    +            smallest = distances[n, k]
    +            smallest_row_index = k
    +
    +    cluster_labels[n] = smallest_row_index
     
    @@ -356,17 +383,6 @@ plt.show()
    -

    So what do we have so far? We have 'picked' \( k \) centroids at random from our -data points. There are other ways of more intelligently choosing their -initializations, however for our purposes randomly is fine. Then we have -initialized an array 'distances' which holds the information of the distance, -or dissimilarity, of every point to of our centroids. Finally, we have -initialized an array 'cluster_labels' which according to our distances array -holds the information of to which centroid every point is assigned. This was the -first pass of our algorithm. Essentially, all we need to do now is repeat the -distance and assignment steps above until we have reached a desired convergence -or a maximum amount of iterations. -

    @@ -393,7 +409,7 @@ or a maximum amount of iterations.

  • 24
  • 25
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs016.html b/doc/pub/week44/html/._week44-bs016.html index bd095ce9f..6db2b4390 100644 --- a/doc/pub/week44/html/._week44-bs016.html +++ b/doc/pub/week44/html/._week44-bs016.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,8 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Continuing

    - +

    Plotting

    @@ -329,50 +330,19 @@ MathJax.Hub.Config({
    -
    max_iterations = 100
    -tolerance = 1e-8
    +  
    fig = plt.figure()
    +ax = fig.add_subplot()
    +unique_cluster_labels = np.unique(cluster_labels)
    +for i in unique_cluster_labels:
    +    ax.scatter(data[cluster_labels == i, 0],
    +               data[cluster_labels == i, 1],
    +               label = i,
    +               alpha = 0.2)
    +    ax.scatter(centroids[:, 0], centroids[:, 1], c='black')
     
    -for iteration in range(max_iterations):
    -    prev_centroids = centroids.copy()
    -    for k in range(n_clusters):
    -        # this array will be used to update our centroid positions
    -        vector_mean = np.zeros(dimensions)
    -        mean_divisor = 0
    -        for n in range(n_samples):
    -            if cluster_labels[n] == k:
    -                vector_mean += data[n, :]
    -                mean_divisor += 1
    +ax.set_title("First Grouping of Points to Centroids")
     
    -        # update according to the k means
    -        centroids[k, :] = vector_mean / mean_divisor
    -
    -    # we find the dissimilarity
    -    for k in range(n_clusters):
    -        for n in range(n_samples):
    -            dist = 0
    -            for d in range(dimensions):
    -                dist += np.abs(data[n, d] - centroids[k, d])**2
    -                distances[n, k] = dist
    -
    -    # assign each point
    -    for n in range(n_samples):
    -        smallest = 1e10
    -        smallest_row_index = 1e10
    -        for k in range(n_clusters):
    -            if distances[n, k] < smallest:
    -                smallest = distances[n, k]
    -                smallest_row_index = k
    -
    -        cluster_labels[n] = smallest_row_index
    -
    -    # convergence criteria
    -    centroid_difference = np.sum(np.abs(centroids - prev_centroids))
    -    if centroid_difference < tolerance:
    -        print(f'Converged at iteration {iteration}')
    -        break
    -
    -    elif iteration == max_iterations:
    -        print(f'Did not converge in {max_iterations} iterations')
    +plt.show()
     
    @@ -388,6 +358,17 @@ tolerance = 1e-
    +

    So what do we have so far? We have 'picked' \( k \) centroids at random from our +data points. There are other ways of more intelligently choosing their +initializations, however for our purposes randomly is fine. Then we have +initialized an array 'distances' which holds the information of the distance, +or dissimilarity, of every point to of our centroids. Finally, we have +initialized an array 'cluster_labels' which according to our distances array +holds the information of to which centroid every point is assigned. This was the +first pass of our algorithm. Essentially, all we need to do now is repeat the +distance and assignment steps above until we have reached a desired convergence +or a maximum amount of iterations. +

    @@ -414,7 +395,7 @@ tolerance = 1e-

  • 25
  • 26
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs017.html b/doc/pub/week44/html/._week44-bs017.html index d367d2664..ec68a9bdf 100644 --- a/doc/pub/week44/html/._week44-bs017.html +++ b/doc/pub/week44/html/._week44-bs017.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,10 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Wrapping it up

    -

    We now have a simple , un-optimized \( k \)-means -clustering implementation. Lets plot the final result -

    +

    Continuing

    @@ -332,47 +331,24 @@ clustering implementation. Lets plot the final result
    -
    fig = plt.figure()
    -ax = fig.add_subplot()
    -unique_cluster_labels = np.unique(cluster_labels)
    -for i in unique_cluster_labels:
    -    ax.scatter(data[cluster_labels == i, 0],
    -               data[cluster_labels == i, 1],
    -               label = i,
    -               alpha = 0.2)
    -    ax.scatter(centroids[:, 0], centroids[:, 1], c='black')
    +  
    max_iterations = 100
    +tolerance = 1e-8
     
    -ax.set_title("Final Result of K-means Clustering")
    +for iteration in range(max_iterations):
    +    prev_centroids = centroids.copy()
    +    for k in range(n_clusters):
    +        # this array will be used to update our centroid positions
    +        vector_mean = np.zeros(dimensions)
    +        mean_divisor = 0
    +        for n in range(n_samples):
    +            if cluster_labels[n] == k:
    +                vector_mean += data[n, :]
    +                mean_divisor += 1
     
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    def naive_kmeans(data, n_clusters=4, max_iterations=100, tolerance=1e-8):
    -    start_time = time.time()
    -
    -    n_samples, dimensions = data.shape
    -    n_clusters = 4
    -    #np.random.seed(2021)
    -    centroids = data[np.random.choice(n_samples, n_clusters, replace=False), :]
    -    distances = np.zeros((n_samples, n_clusters))
    +        # update according to the k means
    +        centroids[k, :] = vector_mean / mean_divisor
     
    +    # we find the dissimilarity
         for k in range(n_clusters):
             for n in range(n_samples):
                 dist = 0
    @@ -380,8 +356,7 @@ plt.show()
                     dist += np.abs(data[n, d] - centroids[k, d])**2
                     distances[n, k] = dist
     
    -    cluster_labels = np.zeros(n_samples, dtype='int')
    -
    +    # assign each point
         for n in range(n_samples):
             smallest = 1e10
             smallest_row_index = 1e10
    @@ -392,46 +367,14 @@ plt.show()
     
             cluster_labels[n] = smallest_row_index
     
    -    for iteration in range(max_iterations):
    -        prev_centroids = centroids.copy()
    -        for k in range(n_clusters):
    -            vector_mean = np.zeros(dimensions)
    -            mean_divisor = 0
    -            for n in range(n_samples):
    -                if cluster_labels[n] == k:
    -                    vector_mean += data[n, :]
    -                    mean_divisor += 1
    +    # convergence criteria
    +    centroid_difference = np.sum(np.abs(centroids - prev_centroids))
    +    if centroid_difference < tolerance:
    +        print(f'Converged at iteration {iteration}')
    +        break
     
    -            centroids[k, :] = vector_mean / mean_divisor
    -
    -        for k in range(n_clusters):
    -            for n in range(n_samples):
    -                dist = 0
    -                for d in range(dimensions):
    -                    dist += np.abs(data[n, d] - centroids[k, d])**2
    -                    distances[n, k] = dist
    -
    -        for n in range(n_samples):
    -            smallest = 1e10
    -            smallest_row_index = 1e10
    -            for k in range(n_clusters):
    -                if distances[n, k] < smallest:
    -                    smallest = distances[n, k]
    -                    smallest_row_index = k
    -
    -            cluster_labels[n] = smallest_row_index
    -
    -        centroid_difference = np.sum(np.abs(centroids - prev_centroids))
    -        if centroid_difference < tolerance:
    -            print(f'Converged at iteration {iteration}')
    -            print(f'Runtime: {time.time() - start_time} seconds')
    -
    -            return cluster_labels, centroids
    -
    -    print(f'Did not converge in {max_iterations} iterations')
    -    print(f'Runtime: {time.time() - start_time} seconds')
    -
    -    return cluster_labels, centroids
    +    elif iteration == max_iterations:
    +        print(f'Did not converge in {max_iterations} iterations')
     
    @@ -473,7 +416,7 @@ plt.show()
  • 26
  • 27
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs018.html b/doc/pub/week44/html/._week44-bs018.html index df3e6ac3b..e3d659802 100644 --- a/doc/pub/week44/html/._week44-bs018.html +++ b/doc/pub/week44/html/._week44-bs018.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,32 +322,133 @@ MathJax.Hub.Config({

     

     

     

    -

    Decision trees, overarching aims

    - -

    We start here with the most basic algorithm, the so-called decision -tree. With this basic algorithm we can in turn build more complex -networks, spanning from homogeneous and heterogenous forests (bagging, -random forests and more) to one of the most popular supervised -algorithms nowadays, the extreme gradient boosting, or just -XGBoost. But let us start with the simplest possible ingredient. +

    Wrapping it up

    +

    We now have a simple , un-optimized \( k \)-means +clustering implementation. Lets plot the final result

    -

    Decision trees are supervised learning algorithms used for both, -classification and regression tasks. -

    -

    The main idea of decision trees -is to find those descriptive features which contain the most -information regarding the target feature and then split the dataset -along the values of these features such that the target feature values -for the resulting underlying datasets are as pure as possible. -

    + +
    +
    +
    +
    +
    +
    fig = plt.figure()
    +ax = fig.add_subplot()
    +unique_cluster_labels = np.unique(cluster_labels)
    +for i in unique_cluster_labels:
    +    ax.scatter(data[cluster_labels == i, 0],
    +               data[cluster_labels == i, 1],
    +               label = i,
    +               alpha = 0.2)
    +    ax.scatter(centroids[:, 0], centroids[:, 1], c='black')
    +
    +ax.set_title("Final Result of K-means Clustering")
    +
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    def naive_kmeans(data, n_clusters=4, max_iterations=100, tolerance=1e-8):
    +    start_time = time.time()
    +
    +    n_samples, dimensions = data.shape
    +    n_clusters = 4
    +    #np.random.seed(2021)
    +    centroids = data[np.random.choice(n_samples, n_clusters, replace=False), :]
    +    distances = np.zeros((n_samples, n_clusters))
    +
    +    for k in range(n_clusters):
    +        for n in range(n_samples):
    +            dist = 0
    +            for d in range(dimensions):
    +                dist += np.abs(data[n, d] - centroids[k, d])**2
    +                distances[n, k] = dist
    +
    +    cluster_labels = np.zeros(n_samples, dtype='int')
    +
    +    for n in range(n_samples):
    +        smallest = 1e10
    +        smallest_row_index = 1e10
    +        for k in range(n_clusters):
    +            if distances[n, k] < smallest:
    +                smallest = distances[n, k]
    +                smallest_row_index = k
    +
    +        cluster_labels[n] = smallest_row_index
    +
    +    for iteration in range(max_iterations):
    +        prev_centroids = centroids.copy()
    +        for k in range(n_clusters):
    +            vector_mean = np.zeros(dimensions)
    +            mean_divisor = 0
    +            for n in range(n_samples):
    +                if cluster_labels[n] == k:
    +                    vector_mean += data[n, :]
    +                    mean_divisor += 1
    +
    +            centroids[k, :] = vector_mean / mean_divisor
    +
    +        for k in range(n_clusters):
    +            for n in range(n_samples):
    +                dist = 0
    +                for d in range(dimensions):
    +                    dist += np.abs(data[n, d] - centroids[k, d])**2
    +                    distances[n, k] = dist
    +
    +        for n in range(n_samples):
    +            smallest = 1e10
    +            smallest_row_index = 1e10
    +            for k in range(n_clusters):
    +                if distances[n, k] < smallest:
    +                    smallest = distances[n, k]
    +                    smallest_row_index = k
    +
    +            cluster_labels[n] = smallest_row_index
    +
    +        centroid_difference = np.sum(np.abs(centroids - prev_centroids))
    +        if centroid_difference < tolerance:
    +            print(f'Converged at iteration {iteration}')
    +            print(f'Runtime: {time.time() - start_time} seconds')
    +
    +            return cluster_labels, centroids
    +
    +    print(f'Did not converge in {max_iterations} iterations')
    +    print(f'Runtime: {time.time() - start_time} seconds')
    +
    +    return cluster_labels, centroids
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    The descriptive features which reproduce best the target/output features are normally said -to be the most informative ones. The process of finding the most -informative feature is done until we accomplish a stopping criteria -where we then finally end up in so called leaf nodes. -

    @@ -372,7 +475,7 @@ where we then finally end up in so called leaf nodes.

  • 27
  • 28
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs019.html b/doc/pub/week44/html/._week44-bs019.html index 74c950c6e..8ac5fb717 100644 --- a/doc/pub/week44/html/._week44-bs019.html +++ b/doc/pub/week44/html/._week44-bs019.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,18 +322,31 @@ MathJax.Hub.Config({

     

     

     

    -

    Basics of a tree

    +

    Decision trees, overarching aims

    -

    A decision tree is typically divided into a root node, the interior nodes, -and the final leaf nodes or just leaves. These entities are then connected by so-called branches. +

    We start here with the most basic algorithm, the so-called decision +tree. With this basic algorithm we can in turn build more complex +networks, spanning from homogeneous and heterogenous forests (bagging, +random forests and more) to one of the most popular supervised +algorithms nowadays, the extreme gradient boosting, or just +XGBoost. But let us start with the simplest possible ingredient.

    -

    The leaf nodes -contain the predictions we will make for new query instances presented -to our trained model. This is possible since the model has -learned the underlying structure of the training data and hence can, -given some assumptions, make predictions about the target feature value -(class) of unseen query instances. +

    Decision trees are supervised learning algorithms used for both, +classification and regression tasks. +

    + +

    The main idea of decision trees +is to find those descriptive features which contain the most +information regarding the target feature and then split the dataset +along the values of these features such that the target feature values +for the resulting underlying datasets are as pure as possible. +

    + +

    The descriptive features which reproduce best the target/output features are normally said +to be the most informative ones. The process of finding the most +informative feature is done until we accomplish a stopping criteria +where we then finally end up in so called leaf nodes.

    @@ -359,7 +374,7 @@ given some assumptions, make predictions about the target feature value

  • 28
  • 29
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs020.html b/doc/pub/week44/html/._week44-bs020.html index 15a5de03e..1fce4cb69 100644 --- a/doc/pub/week44/html/._week44-bs020.html +++ b/doc/pub/week44/html/._week44-bs020.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,9 +322,19 @@ MathJax.Hub.Config({

     

     

     

    -

    A Sketch of a Tree, Regression problem

    +

    Basics of a tree

    - +

    A decision tree is typically divided into a root node, the interior nodes, +and the final leaf nodes or just leaves. These entities are then connected by so-called branches. +

    + +

    The leaf nodes +contain the predictions we will make for new query instances presented +to our trained model. This is possible since the model has +learned the underlying structure of the training data and hence can, +given some assumptions, make predictions about the target feature value +(class) of unseen query instances. +

    @@ -349,7 +361,7 @@ MathJax.Hub.Config({

  • 29
  • 30
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs021.html b/doc/pub/week44/html/._week44-bs021.html index 86a33d43a..22009764b 100644 --- a/doc/pub/week44/html/._week44-bs021.html +++ b/doc/pub/week44/html/._week44-bs021.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,9 +322,9 @@ MathJax.Hub.Config({

     

     

     

    -

    A Sketch of a Tree, Classification problem

    +

    A Sketch of a Tree, Regression problem

    - +

    @@ -349,7 +351,7 @@ MathJax.Hub.Config({

  • 30
  • 31
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs022.html b/doc/pub/week44/html/._week44-bs022.html index 985655649..3d17dd1c5 100644 --- a/doc/pub/week44/html/._week44-bs022.html +++ b/doc/pub/week44/html/._week44-bs022.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,15 +322,9 @@ MathJax.Hub.Config({

     

     

     

    -

    A typical Decision Tree with its pertinent Jargon, Classification Problem

    +

    A Sketch of a Tree, Classification problem

    -

    -
    -

    -
    -

    - -

    This tree was produced using the Wisconsin cancer data (discussed here as well, see code examples below) using Scikit-Learn's decision tree classifier. Here we have used the so-called gini index (see below) to split the various branches.

    +

    @@ -355,7 +351,7 @@ MathJax.Hub.Config({

  • 31
  • 32
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs023.html b/doc/pub/week44/html/._week44-bs023.html index 60c7dbfbf..f8a6a9870 100644 --- a/doc/pub/week44/html/._week44-bs023.html +++ b/doc/pub/week44/html/._week44-bs023.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,19 +322,15 @@ MathJax.Hub.Config({

     

     

     

    -

    General Features

    +

    A typical Decision Tree with its pertinent Jargon, Classification Problem

    -

    The overarching approach to decision trees is a top-down approach.

    +

    +
    +

    +
    +

    -
      -
    • A leaf provides the classification of a given instance.
    • -
    • A node specifies a test of some attribute of the instance.
    • -
    • A branch corresponds to a possible values of an attribute.
    • -
    • An instance is classified by starting at the root node of the tree, testing the attribute specified by this node, then moving down the tree branch corresponding to the value of the attribute in the given example.
    • -
    -

    This process is then repeated for the subtree rooted at the new -node. -

    +

    This tree was produced using the Wisconsin cancer data (discussed here as well, see code examples below) using Scikit-Learn's decision tree classifier. Here we have used the so-called gini index (see below) to split the various branches.

    @@ -359,7 +357,7 @@ node.

  • 32
  • 33
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs024.html b/doc/pub/week44/html/._week44-bs024.html index 82d33b469..d09adc34e 100644 --- a/doc/pub/week44/html/._week44-bs024.html +++ b/doc/pub/week44/html/._week44-bs024.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,20 +322,20 @@ MathJax.Hub.Config({

     

     

     

    -

    How do we set it up?

    +

    General Features

    -

    In simplified terms, the process of training a decision tree and -predicting the target features of query instances is as follows: +

    The overarching approach to decision trees is a top-down approach.

    + +
      +
    • A leaf provides the classification of a given instance.
    • +
    • A node specifies a test of some attribute of the instance.
    • +
    • A branch corresponds to a possible values of an attribute.
    • +
    • An instance is classified by starting at the root node of the tree, testing the attribute specified by this node, then moving down the tree branch corresponding to the value of the attribute in the given example.
    • +
    +

    This process is then repeated for the subtree rooted at the new +node.

    -
      -
    1. Present a dataset containing of a number of training instances characterized by a number of descriptive features and a target feature
    2. -
    3. Train the decision tree model by continuously splitting the target feature along the values of the descriptive features using a measure of information gain during the training process
    4. -
    5. Grow the tree until we accomplish a stopping criteria create leaf nodes which represent the predictions we want to make for new query instances
    6. -
    7. Show query instances to the tree and run down the tree until we arrive at leaf nodes
    8. -
    -

    Then we are essentially done!

    -

      @@ -359,7 +361,7 @@ predicting the target features of query instances is as follows:
    • 33
    • 34
    • ...
    • -
    • 62
    • +
    • 63
    • »
    diff --git a/doc/pub/week44/html/._week44-bs025.html b/doc/pub/week44/html/._week44-bs025.html index 5d198c295..a7cfe2d8a 100644 --- a/doc/pub/week44/html/._week44-bs025.html +++ b/doc/pub/week44/html/._week44-bs025.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,117 +322,19 @@ MathJax.Hub.Config({

     

     

     

    -

    Decision trees and Regression

    +

    How do we set it up?

    - -
    -
    -
    -
    -
    -
    import numpy as np
    -import matplotlib.pyplot as plt
    -from sklearn.preprocessing import PolynomialFeatures
    -from sklearn.linear_model import LinearRegression
    -
    -steps=250
    -
    -distance=0
    -x=0
    -distance_list=[]
    -steps_list=[]
    -while x<steps:
    -    distance+=np.random.randint(-1,2)
    -    distance_list.append(distance)
    -    x+=1
    -    steps_list.append(x)
    -plt.plot(steps_list,distance_list, color='green', label="Random Walk Data")
    -
    -steps_list=np.asarray(steps_list)
    -distance_list=np.asarray(distance_list)
    -
    -X=steps_list[:,np.newaxis]
    -
    -#Polynomial fits
    -
    -#Degree 2
    -poly_features=PolynomialFeatures(degree=2, include_bias=False)
    -X_poly=poly_features.fit_transform(X)
    -
    -lin_reg=LinearRegression()
    -poly_fit=lin_reg.fit(X_poly,distance_list)
    -b=lin_reg.coef_
    -c=lin_reg.intercept_
    -print ("2nd degree coefficients:")
    -print ("zero power: ",c)
    -print ("first power: ", b[0])
    -print ("second power: ",b[1])
    -
    -z = np.arange(0, steps, .01)
    -z_mod=b[1]*z**2+b[0]*z+c
    -
    -fit_mod=b[1]*X**2+b[0]*X+c
    -plt.plot(z, z_mod, color='r', label="2nd Degree Fit")
    -plt.title("Polynomial Regression")
    -
    -plt.xlabel("Steps")
    -plt.ylabel("Distance")
    -
    -#Degree 10
    -poly_features10=PolynomialFeatures(degree=10, include_bias=False)
    -X_poly10=poly_features10.fit_transform(X)
    -
    -poly_fit10=lin_reg.fit(X_poly10,distance_list)
    -
    -y_plot=poly_fit10.predict(X_poly10)
    -plt.plot(X, y_plot, color='black', label="10th Degree Fit")
    -
    -plt.legend()
    -plt.show()
    -
    -
    -#Decision Tree Regression
    -from sklearn.tree import DecisionTreeRegressor
    -regr_1=DecisionTreeRegressor(max_depth=2)
    -regr_2=DecisionTreeRegressor(max_depth=5)
    -regr_3=DecisionTreeRegressor(max_depth=7)
    -regr_1.fit(X, distance_list)
    -regr_2.fit(X, distance_list)
    -regr_3.fit(X, distance_list)
    -
    -X_test = np.arange(0.0, steps, 0.01)[:, np.newaxis]
    -y_1 = regr_1.predict(X_test)
    -y_2 = regr_2.predict(X_test)
    -y_3=regr_3.predict(X_test)
    -
    -# Plot the results
    -plt.figure()
    -plt.scatter(X, distance_list, s=2.5, c="black", label="data")
    -plt.plot(X_test, y_1, color="red",
    -         label="max_depth=2", linewidth=2)
    -plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
    -plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
    -
    -plt.xlabel("Data")
    -plt.ylabel("Darget")
    -plt.title("Decision Tree Regression")
    -plt.legend()
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    In simplified terms, the process of training a decision tree and +predicting the target features of query instances is as follows: +

    +
      +
    1. Present a dataset containing of a number of training instances characterized by a number of descriptive features and a target feature
    2. +
    3. Train the decision tree model by continuously splitting the target feature along the values of the descriptive features using a measure of information gain during the training process
    4. +
    5. Grow the tree until we accomplish a stopping criteria create leaf nodes which represent the predictions we want to make for new query instances
    6. +
    7. Show query instances to the tree and run down the tree until we arrive at leaf nodes
    8. +
    +

    Then we are essentially done!

    @@ -457,7 +361,7 @@ plt.show()

  • 34
  • 35
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs026.html b/doc/pub/week44/html/._week44-bs026.html index 30a23640b..b31f290cc 100644 --- a/doc/pub/week44/html/._week44-bs026.html +++ b/doc/pub/week44/html/._week44-bs026.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,28 +322,117 @@ MathJax.Hub.Config({

     

     

     

    -

    Building a tree, regression

    +

    Decision trees and Regression

    -

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

    How do we construct the regions \( R_1,\dots,R_J \)? In theory, the -regions could have any shape. However, we choose to divide the -predictor space into high-dimensional rectangles, or boxes, for -simplicity and for ease of interpretation of the resulting predictive -model. The goal is to find boxes \( R_1,\dots,R_J \) that minimize the -MSE, given by -

    + +
    +
    +
    +
    +
    +
    import numpy as np
    +import matplotlib.pyplot as plt
    +from sklearn.preprocessing import PolynomialFeatures
    +from sklearn.linear_model import LinearRegression
     
    -$$
    -\sum_{j=1}^J\sum_{i\in R_j}(y_i-\overline{y}_{R_j})^2,
    -$$
    +steps=250
    +
    +distance=0
    +x=0
    +distance_list=[]
    +steps_list=[]
    +while x<steps:
    +    distance+=np.random.randint(-1,2)
    +    distance_list.append(distance)
    +    x+=1
    +    steps_list.append(x)
    +plt.plot(steps_list,distance_list, color='green', label="Random Walk Data")
    +
    +steps_list=np.asarray(steps_list)
    +distance_list=np.asarray(distance_list)
    +
    +X=steps_list[:,np.newaxis]
    +
    +#Polynomial fits
    +
    +#Degree 2
    +poly_features=PolynomialFeatures(degree=2, include_bias=False)
    +X_poly=poly_features.fit_transform(X)
    +
    +lin_reg=LinearRegression()
    +poly_fit=lin_reg.fit(X_poly,distance_list)
    +b=lin_reg.coef_
    +c=lin_reg.intercept_
    +print ("2nd degree coefficients:")
    +print ("zero power: ",c)
    +print ("first power: ", b[0])
    +print ("second power: ",b[1])
    +
    +z = np.arange(0, steps, .01)
    +z_mod=b[1]*z**2+b[0]*z+c
    +
    +fit_mod=b[1]*X**2+b[0]*X+c
    +plt.plot(z, z_mod, color='r', label="2nd Degree Fit")
    +plt.title("Polynomial Regression")
    +
    +plt.xlabel("Steps")
    +plt.ylabel("Distance")
    +
    +#Degree 10
    +poly_features10=PolynomialFeatures(degree=10, include_bias=False)
    +X_poly10=poly_features10.fit_transform(X)
    +
    +poly_fit10=lin_reg.fit(X_poly10,distance_list)
    +
    +y_plot=poly_fit10.predict(X_poly10)
    +plt.plot(X, y_plot, color='black', label="10th Degree Fit")
    +
    +plt.legend()
    +plt.show()
    +
    +
    +#Decision Tree Regression
    +from sklearn.tree import DecisionTreeRegressor
    +regr_1=DecisionTreeRegressor(max_depth=2)
    +regr_2=DecisionTreeRegressor(max_depth=5)
    +regr_3=DecisionTreeRegressor(max_depth=7)
    +regr_1.fit(X, distance_list)
    +regr_2.fit(X, distance_list)
    +regr_3.fit(X, distance_list)
    +
    +X_test = np.arange(0.0, steps, 0.01)[:, np.newaxis]
    +y_1 = regr_1.predict(X_test)
    +y_2 = regr_2.predict(X_test)
    +y_3=regr_3.predict(X_test)
    +
    +# Plot the results
    +plt.figure()
    +plt.scatter(X, distance_list, s=2.5, c="black", label="data")
    +plt.plot(X_test, y_1, color="red",
    +         label="max_depth=2", linewidth=2)
    +plt.plot(X_test, y_2, color="green", label="max_depth=5", linewidth=2)
    +plt.plot(X_test, y_3, color="m", label="max_depth=7", linewidth=2)
    +
    +plt.xlabel("Data")
    +plt.ylabel("Darget")
    +plt.title("Decision Tree Regression")
    +plt.legend()
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    where \( \overline{y}_{R_j} \) is the mean response for the training observations -within box \( j \). -

    @@ -368,7 +459,7 @@ within box \( j \).

  • 35
  • 36
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs027.html b/doc/pub/week44/html/._week44-bs027.html index a28e36119..e2f65cf08 100644 --- a/doc/pub/week44/html/._week44-bs027.html +++ b/doc/pub/week44/html/._week44-bs027.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,20 +322,27 @@ MathJax.Hub.Config({

     

     

     

    -

    A top-down approach, recursive binary splitting

    +

    Building a tree, regression

    -

    Unfortunately, it is computationally infeasible to consider every -possible partition of the feature space into \( J \) boxes. The common -strategy is to take a top-down approach +

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

    How do we construct the regions \( R_1,\dots,R_J \)? In theory, the +regions could have any shape. However, we choose to divide the +predictor space into high-dimensional rectangles, or boxes, for +simplicity and for ease of interpretation of the resulting predictive +model. The goal is to find boxes \( R_1,\dots,R_J \) that minimize the +MSE, given by

    -

    The approach is top-down because it begins at the top of the tree (all -observations belong to a single region) and then successively splits -the predictor space; each split is indicated via two new branches -further down on the tree. It is greedy because at each step of the -tree-building process, the best split is made at that particular step, -rather than looking ahead and picking a split that will lead to a -better tree in some future step. +$$ +\sum_{j=1}^J\sum_{i\in R_j}(y_i-\overline{y}_{R_j})^2, +$$ + +

    where \( \overline{y}_{R_j} \) is the mean response for the training observations +within box \( j \).

    @@ -361,7 +370,7 @@ better tree in some future step.

  • 36
  • 37
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs028.html b/doc/pub/week44/html/._week44-bs028.html index ef3978c60..346168e4e 100644 --- a/doc/pub/week44/html/._week44-bs028.html +++ b/doc/pub/week44/html/._week44-bs028.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,52 +322,20 @@ MathJax.Hub.Config({

     

     

     

    -

    Making a tree

    +

    A top-down approach, recursive binary splitting

    -

    In order to implement the recursive binary splitting we start by selecting -the predictor \( x_j \) and a cutpoint \( s \) that splits the predictor space into two regions \( R_1 \) and \( R_2 \) -

    -$$ -\left\{X\vert x_j < s\right\}, -$$ - -

    and

    -$$ -\left\{X\vert x_j \geq s\right\}, -$$ - -

    so that we obtain the lowest MSE, that is

    -$$ -\sum_{i:x_i\in R_j}(y_i-\overline{y}_{R_1})^2+\sum_{i:x_i\in R_2}(y_i-\overline{y}_{R_2})^2, -$$ - -

    which we want to minimize by considering all predictors -\( x_1,x_2,\dots,x_p \). We consider also all possible values of \( s \) for -each predictor. These values could be determined by randomly assigned -numbers or by starting at the midpoint and then proceed till we find -an optimal value. +

    Unfortunately, it is computationally infeasible to consider every +possible partition of the feature space into \( J \) boxes. The common +strategy is to take a top-down approach

    -

    For any \( j \) and \( s \), we define the pair of half-planes where -\( \overline{y}_{R_1} \) is the mean response for the training -observations in \( R_1(j,s) \), and \( \overline{y}_{R_2} \) is the mean -response for the training observations in \( R_2(j,s) \). -

    - -

    Finding the values of \( j \) and \( s \) that minimize the above equation can be -done quite quickly, especially when the number of features \( p \) is not -too large. -

    - -

    Next, we repeat the process, looking -for the best predictor and best cutpoint in order to split the data -further so as to minimize the MSE within each of the resulting -regions. However, this time, instead of splitting the entire predictor -space, we split one of the two previously identified regions. We now -have three regions. Again, we look to split one of these three regions -further, so as to minimize the MSE. The process continues until a -stopping criterion is reached; for instance, we may continue until no -region contains more than five observations. +

    The approach is top-down because it begins at the top of the tree (all +observations belong to a single region) and then successively splits +the predictor space; each split is indicated via two new branches +further down on the tree. It is greedy because at each step of the +tree-building process, the best split is made at that particular step, +rather than looking ahead and picking a split that will lead to a +better tree in some future step.

    @@ -393,7 +363,7 @@ region contains more than five observations.

  • 37
  • 38
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs029.html b/doc/pub/week44/html/._week44-bs029.html index b75a82751..4293f1d53 100644 --- a/doc/pub/week44/html/._week44-bs029.html +++ b/doc/pub/week44/html/._week44-bs029.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -319,24 +321,54 @@ MathJax.Hub.Config({

     

     

     

    - -

    Pruning the tree

    + +

    Making a tree

    -

    The above procedure is rather straightforward, but leads often to -overfitting and unnecessarily large and complicated trees. The basic -idea is to grow a large tree \( T_0 \) and then prune it back in order to -obtain a subtree. A smaller tree with fewer splits (fewer regions) can -lead to smaller variance and better interpretation at the cost of a -little more bias. +

    In order to implement the recursive binary splitting we start by selecting +the predictor \( x_j \) and a cutpoint \( s \) that splits the predictor space into two regions \( R_1 \) and \( R_2 \) +

    +$$ +\left\{X\vert x_j < s\right\}, +$$ + +

    and

    +$$ +\left\{X\vert x_j \geq s\right\}, +$$ + +

    so that we obtain the lowest MSE, that is

    +$$ +\sum_{i:x_i\in R_j}(y_i-\overline{y}_{R_1})^2+\sum_{i:x_i\in R_2}(y_i-\overline{y}_{R_2})^2, +$$ + +

    which we want to minimize by considering all predictors +\( x_1,x_2,\dots,x_p \). We consider also all possible values of \( s \) for +each predictor. These values could be determined by randomly assigned +numbers or by starting at the midpoint and then proceed till we find +an optimal value.

    -

    The so-called Cost complexity pruning algorithm gives us a -way to do just this. Rather than considering every possible subtree, -we consider a sequence of trees indexed by a nonnegative tuning -parameter \( \alpha \). +

    For any \( j \) and \( s \), we define the pair of half-planes where +\( \overline{y}_{R_1} \) is the mean response for the training +observations in \( R_1(j,s) \), and \( \overline{y}_{R_2} \) is the mean +response for the training observations in \( R_2(j,s) \).

    -

    Read more at the following Scikit-Learn link on pruning.

    +

    Finding the values of \( j \) and \( s \) that minimize the above equation can be +done quite quickly, especially when the number of features \( p \) is not +too large. +

    + +

    Next, we repeat the process, looking +for the best predictor and best cutpoint in order to split the data +further so as to minimize the MSE within each of the resulting +regions. However, this time, instead of splitting the entire predictor +space, we split one of the two previously identified regions. We now +have three regions. Again, we look to split one of these three regions +further, so as to minimize the MSE. The process continues until a +stopping criterion is reached; for instance, we may continue until no +region contains more than five observations. +

    @@ -363,7 +395,7 @@ parameter \( \alpha \).

  • 38
  • 39
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs030.html b/doc/pub/week44/html/._week44-bs030.html index 85dc15f1a..30697795e 100644 --- a/doc/pub/week44/html/._week44-bs030.html +++ b/doc/pub/week44/html/._week44-bs030.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -319,36 +321,24 @@ MathJax.Hub.Config({

     

     

     

    - -

    Cost complexity pruning

    + +

    Pruning the tree

    -

    For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that

    -$$ -\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T}, -$$ - -

    is as small as possible. Here \( \overline{T} \) is -the number of terminal nodes of the tree \( T \) , \( R_m \) is the -rectangle (i.e. the subset of predictor space) corresponding to the \( m \)-th terminal node. +

    The above procedure is rather straightforward, but leads often to +overfitting and unnecessarily large and complicated trees. The basic +idea is to grow a large tree \( T_0 \) and then prune it back in order to +obtain a subtree. A smaller tree with fewer splits (fewer regions) can +lead to smaller variance and better interpretation at the cost of a +little more bias.

    -

    The tuning parameter \( \alpha \) controls a trade-off between the subtree’s -complexity and its fit to the training data. When \( \alpha = 0 \), then the -subtree \( T \) will simply equal \( T_0 \), -because then the above equation just measures the -training error. -However, as \( \alpha \) increases, there is a price to pay for -having a tree with many terminal nodes. The above equation will -tend to be minimized for a smaller subtree. +

    The so-called Cost complexity pruning algorithm gives us a +way to do just this. Rather than considering every possible subtree, +we consider a sequence of trees indexed by a nonnegative tuning +parameter \( \alpha \).

    -

    It turns out that as we increase \( \alpha \) from zero -branches get pruned from the tree in a nested and predictable fashion, -so obtaining the whole sequence of subtrees as a function of \( \alpha \) is -easy. We can select a value of \( \alpha \) using a validation set or using -cross-validation. We then return to the full data set and obtain the -subtree corresponding to \( \alpha \). -

    +

    Read more at the following Scikit-Learn link on pruning.

    @@ -375,7 +365,7 @@ subtree corresponding to \( \alpha \).

  • 39
  • 40
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs031.html b/doc/pub/week44/html/._week44-bs031.html index 87cf566be..0813c9ac6 100644 --- a/doc/pub/week44/html/._week44-bs031.html +++ b/doc/pub/week44/html/._week44-bs031.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,26 +322,35 @@ MathJax.Hub.Config({

     

     

     

    -

    Schematic Regression Procedure

    +

    Cost complexity pruning

    -
    -
    - +

    For each value of \( \alpha \) there corresponds a subtree \( T \in T_0 \) such that

    +$$ +\sum_{m=1}^{\overline{T}}\sum_{i:x_i\in R_m}(y_i-\overline{y}_{R_m})^2+\alpha\overline{T}, +$$ -
      -
    1. Use recursive binary splitting to grow a large tree on the training data, stopping only when each terminal node has fewer than some minimum number of observations.
    2. -
    3. Apply cost complexity pruning to the large tree in order to obtain a sequence of best subtrees, as a function of \( \alpha \).
    4. -
    5. Use for example \( K \)-fold cross-validation to choose \( \alpha \). Divide the training observations into \( K \) folds. For each \( k=1,2,\dots,K \) we:
    6. -
        -
      • repeat steps 1 and 2 on all but the \( k \)-th fold of the training data.
      • -
      • Then we valuate the mean squared prediction error on the data in the left-out \( k \)-th fold, as a function of \( \alpha \).
      • -
      • Finally we average the results for each value of \( \alpha \), and pick \( \alpha \) to minimize the average error.
      • -
      -
    7. Return the subtree from Step 2 that corresponds to the chosen value of \( \alpha \).
    8. -
    -
    -
    +

    is as small as possible. Here \( \overline{T} \) is +the number of terminal nodes of the tree \( T \) , \( R_m \) is the +rectangle (i.e. the subset of predictor space) corresponding to the \( m \)-th terminal node. +

    +

    The tuning parameter \( \alpha \) controls a trade-off between the subtree’s +complexity and its fit to the training data. When \( \alpha = 0 \), then the +subtree \( T \) will simply equal \( T_0 \), +because then the above equation just measures the +training error. +However, as \( \alpha \) increases, there is a price to pay for +having a tree with many terminal nodes. The above equation will +tend to be minimized for a smaller subtree. +

    + +

    It turns out that as we increase \( \alpha \) from zero +branches get pruned from the tree in a nested and predictable fashion, +so obtaining the whole sequence of subtrees as a function of \( \alpha \) is +easy. We can select a value of \( \alpha \) using a validation set or using +cross-validation. We then return to the full data set and obtain the +subtree corresponding to \( \alpha \). +

    @@ -366,7 +377,7 @@ MathJax.Hub.Config({

  • 40
  • 41
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs032.html b/doc/pub/week44/html/._week44-bs032.html index a0da62843..6a8dd15bf 100644 --- a/doc/pub/week44/html/._week44-bs032.html +++ b/doc/pub/week44/html/._week44-bs032.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,21 +322,26 @@ MathJax.Hub.Config({

     

     

     

    -

    A Classification Tree

    +

    Schematic Regression Procedure

    + +
    +
    + + +
      +
    1. Use recursive binary splitting to grow a large tree on the training data, stopping only when each terminal node has fewer than some minimum number of observations.
    2. +
    3. Apply cost complexity pruning to the large tree in order to obtain a sequence of best subtrees, as a function of \( \alpha \).
    4. +
    5. Use for example \( K \)-fold cross-validation to choose \( \alpha \). Divide the training observations into \( K \) folds. For each \( k=1,2,\dots,K \) we:
    6. +
        +
      • repeat steps 1 and 2 on all but the \( k \)-th fold of the training data.
      • +
      • Then we valuate the mean squared prediction error on the data in the left-out \( k \)-th fold, as a function of \( \alpha \).
      • +
      • Finally we average the results for each value of \( \alpha \), and pick \( \alpha \) to minimize the average error.
      • +
      +
    7. Return the subtree from Step 2 that corresponds to the chosen value of \( \alpha \).
    8. +
    +
    +
    -

    A classification tree is very similar to a regression tree, except -that it is used to predict a qualitative response rather than a -quantitative one. Recall that for a regression tree, the predicted -response for an observation is given by the mean response of the -training observations that belong to the same terminal node. In -contrast, for a classification tree, we predict that each observation -belongs to the most commonly occurring class of training observations -in the region to which it belongs. In interpreting the results of a -classification tree, we are often interested not only in the class -prediction corresponding to a particular terminal node region, but -also in the class proportions among the training observations that -fall into that region. -

    @@ -361,7 +368,7 @@ fall into that region.

  • 41
  • 42
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs033.html b/doc/pub/week44/html/._week44-bs033.html index 1d6afa52e..7c3586cda 100644 --- a/doc/pub/week44/html/._week44-bs033.html +++ b/doc/pub/week44/html/._week44-bs033.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,25 +322,20 @@ MathJax.Hub.Config({

     

     

     

    -

    Growing a classification tree

    +

    A Classification Tree

    -

    The task of growing a -classification tree is quite similar to the task of growing a -regression tree. Just as in the regression setting, we use recursive -binary splitting to grow a classification tree. However, in the -classification setting, the MSE cannot be used as a criterion for making -the binary splits. A natural alternative to MSE is the classification -error rate. Since we plan to assign an observation in a given region -to the most commonly occurring error rate class of training -observations in that region, the classification error rate is simply -the fraction of the training observations in that region that do not -belong to the most common class. -

    - -

    When building a classification tree, either the Gini index or the -entropy are typically used to evaluate the quality of a particular -split, since these two approaches are more sensitive to node purity -than is the classification error rate. +

    A classification tree is very similar to a regression tree, except +that it is used to predict a qualitative response rather than a +quantitative one. Recall that for a regression tree, the predicted +response for an observation is given by the mean response of the +training observations that belong to the same terminal node. In +contrast, for a classification tree, we predict that each observation +belongs to the most commonly occurring class of training observations +in the region to which it belongs. In interpreting the results of a +classification tree, we are often interested not only in the class +prediction corresponding to a particular terminal node region, but +also in the class proportions among the training observations that +fall into that region.

    @@ -366,7 +363,7 @@ than is the classification error rate.

  • 42
  • 43
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs034.html b/doc/pub/week44/html/._week44-bs034.html index 90a6b3b87..f0fb602e8 100644 --- a/doc/pub/week44/html/._week44-bs034.html +++ b/doc/pub/week44/html/._week44-bs034.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,49 +322,27 @@ MathJax.Hub.Config({

     

     

     

    -

    Classification tree, how to split nodes

    +

    Growing a classification tree

    -

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

    The task of growing a +classification tree is quite similar to the task of growing a +regression tree. Just as in the regression setting, we use recursive +binary splitting to grow a classification tree. However, in the +classification setting, the MSE cannot be used as a criterion for making +the binary splits. A natural alternative to MSE is the classification +error rate. Since we plan to assign an observation in a given region +to the most commonly occurring error rate class of training +observations in that region, the classification error rate is simply +the fraction of the training observations in that region that do not +belong to the most common class.

    -

    We define a PDF \( p_{mk} \) that represents the number of observations of -a class \( k \) in a region \( R_m \) with \( N_m \) observations. We represent -this likelihood function in terms of the proportion \( I(y_i=k) \) of -observations of this class in the region \( R_m \) as +

    When building a classification tree, either the Gini index or the +entropy are typically used to evaluate the quality of a particular +split, since these two approaches are more sensitive to node purity +than is the classification error rate.

    -$$ -p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i=k). -$$ - -

    We let \( p_{mk} \) represent the majority class of observations in region -\( m \). The three most common ways of splitting a node are given by -

    - -
      -
    • Misclassification error
    • -
    -$$ -p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i\ne k) = 1-p_{mk}. -$$ - -
      -
    • Gini index \( g \)
    • -
    -$$ -g = \sum_{k=1}^K p_{mk}(1-p_{mk}). -$$ - -
      -
    • Information entropy or just entropy \( s \)
    • -
    -$$ -s = -\sum_{k=1}^K p_{mk}\log{p_{mk}}. -$$ - -

    diff --git a/doc/pub/week44/html/._week44-bs035.html b/doc/pub/week44/html/._week44-bs035.html index 57abf2de5..ee6d072ba 100644 --- a/doc/pub/week44/html/._week44-bs035.html +++ b/doc/pub/week44/html/._week44-bs035.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,61 +322,47 @@ MathJax.Hub.Config({

     

     

     

    -

    Visualizing the Tree, Classification

    +

    Classification tree, how to split nodes

    - -
    -
    -
    -
    -
    -
    import os
    -from sklearn.datasets import load_breast_cancer
    -from sklearn.tree import DecisionTreeClassifier
    -from sklearn.model_selection import train_test_split
    -from sklearn.metrics import confusion_matrix
    -from sklearn.tree import export_graphviz
    +

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

    -from IPython.display import Image -from pydot import graph_from_dot_data -import pandas as pd -import numpy as np +

    We define a PDF \( p_{mk} \) that represents the number of observations of +a class \( k \) in a region \( R_m \) with \( N_m \) observations. We represent +this likelihood function in terms of the proportion \( I(y_i=k) \) of +observations of this class in the region \( R_m \) as +

    +$$ +p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i=k). +$$ -cancer = load_breast_cancer() -X = pd.DataFrame(cancer.data, columns=cancer.feature_names) -print(X) -y = pd.Categorical.from_codes(cancer.target, cancer.target_names) -y = pd.get_dummies(y) -print(y) -X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1) -tree_clf = DecisionTreeClassifier(max_depth=5) -tree_clf.fit(X_train, y_train) +

    We let \( p_{mk} \) represent the majority class of observations in region +\( m \). The three most common ways of splitting a node are given by +

    -export_graphviz( - tree_clf, - out_file="DataFiles/cancer.dot", - feature_names=cancer.feature_names, - class_names=cancer.target_names, - rounded=True, - filled=True -) -cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png' -os.system(cmd) -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +
      +
    • Misclassification error
    • +
    +$$ +p_{mk} = \frac{1}{N_m}\sum_{x_i\in R_m}I(y_i\ne k) = 1-p_{mk}. +$$ + +
      +
    • Gini index \( g \)
    • +
    +$$ +g = \sum_{k=1}^K p_{mk}(1-p_{mk}). +$$ + +
      +
    • Information entropy or just entropy \( s \)
    • +
    +$$ +s = -\sum_{k=1}^K p_{mk}\log{p_{mk}}. +$$

    @@ -402,7 +390,7 @@ os.system(cmd)

  • 44
  • 45
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs036.html b/doc/pub/week44/html/._week44-bs036.html index 86edfad4d..7b410ebee 100644 --- a/doc/pub/week44/html/._week44-bs036.html +++ b/doc/pub/week44/html/._week44-bs036.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Visualizing the Tree, The Moons

    +

    Visualizing the Tree, Classification

    @@ -328,29 +330,38 @@ MathJax.Hub.Config({
    -
    # Common imports
    -import numpy as np
    -from sklearn.model_selection import  train_test_split 
    +  
    import os
    +from sklearn.datasets import load_breast_cancer
     from sklearn.tree import DecisionTreeClassifier
    -from sklearn.datasets import make_moons
    +from sklearn.model_selection import train_test_split
    +from sklearn.metrics import confusion_matrix
     from sklearn.tree import export_graphviz
    +
    +from IPython.display import Image 
     from pydot import graph_from_dot_data
     import pandas as pd
    -import os
    +import numpy as np
     
    -np.random.seed(42)
    -X, y = make_moons(n_samples=100, noise=0.25, random_state=53)
    -X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=0)
    +
    +cancer = load_breast_cancer()
    +X = pd.DataFrame(cancer.data, columns=cancer.feature_names)
    +print(X)
    +y = pd.Categorical.from_codes(cancer.target, cancer.target_names)
    +y = pd.get_dummies(y)
    +print(y)
    +X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
     tree_clf = DecisionTreeClassifier(max_depth=5)
     tree_clf.fit(X_train, y_train)
     
     export_graphviz(
         tree_clf,
    -    out_file="DataFiles/moons.dot",
    +    out_file="DataFiles/cancer.dot",
    +    feature_names=cancer.feature_names,
    +    class_names=cancer.target_names,
         rounded=True,
         filled=True
     )
    -cmd = 'dot -Tpng DataFiles/moons.dot -o DataFiles/moons.png'
    +cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'
     os.system(cmd)
     
    @@ -393,7 +404,7 @@ os.system(cmd)
  • 45
  • 46
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs037.html b/doc/pub/week44/html/._week44-bs037.html index ba789cd3a..1b223abaa 100644 --- a/doc/pub/week44/html/._week44-bs037.html +++ b/doc/pub/week44/html/._week44-bs037.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,10 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Other ways of visualizing the trees

    - -

    Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.

    - +

    Visualizing the Tree, The Moons

    @@ -331,13 +330,30 @@ MathJax.Hub.Config({
    -
    from sklearn.datasets import load_iris
    -from sklearn import tree
    -X, y = load_iris(return_X_y=True)
    -tree_clf = tree.DecisionTreeClassifier()
    -tree_clf = tree_clf.fit(X, y)
    -# and then plot the tree
    -tree.plot_tree(tree_clf) 
    +  
    # Common imports
    +import numpy as np
    +from sklearn.model_selection import  train_test_split 
    +from sklearn.tree import DecisionTreeClassifier
    +from sklearn.datasets import make_moons
    +from sklearn.tree import export_graphviz
    +from pydot import graph_from_dot_data
    +import pandas as pd
    +import os
    +
    +np.random.seed(42)
    +X, y = make_moons(n_samples=100, noise=0.25, random_state=53)
    +X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=0)
    +tree_clf = DecisionTreeClassifier(max_depth=5)
    +tree_clf.fit(X_train, y_train)
    +
    +export_graphviz(
    +    tree_clf,
    +    out_file="DataFiles/moons.dot",
    +    rounded=True,
    +    filled=True
    +)
    +cmd = 'dot -Tpng DataFiles/moons.dot -o DataFiles/moons.png'
    +os.system(cmd)
     
    @@ -379,7 +395,7 @@ tree.plot_tree(tree_clf)
  • 46
  • 47
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs038.html b/doc/pub/week44/html/._week44-bs038.html index e0da8b467..b4086f7f9 100644 --- a/doc/pub/week44/html/._week44-bs038.html +++ b/doc/pub/week44/html/._week44-bs038.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,11 +322,9 @@ MathJax.Hub.Config({

     

     

     

    -

    Printing out as text

    +

    Other ways of visualizing the trees

    -

    Alternatively, the tree can also be exported in textual format with the function exporttext. -This method doesn’t require the installation of external libraries and is more compact: -

    +

    Scikit-Learn has also another way to visualize the trees which is very useful, here with the Iris data.

    @@ -334,13 +334,12 @@ This method doesn’t require the installation of external libraries and is
    from sklearn.datasets import load_iris
    -from sklearn.tree import DecisionTreeClassifier
    -from sklearn.tree import export_text
    -iris = load_iris()
    -decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
    -decision_tree = decision_tree.fit(iris.data, iris.target)
    -r = export_text(decision_tree, feature_names=iris['feature_names'])
    -print(r)
    +from sklearn import tree
    +X, y = load_iris(return_X_y=True)
    +tree_clf = tree.DecisionTreeClassifier()
    +tree_clf = tree_clf.fit(X, y)
    +# and then plot the tree
    +tree.plot_tree(tree_clf) 
     
    @@ -382,7 +381,7 @@ r = export_text(decision_tree, feature_names
  • 47
  • 48
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs039.html b/doc/pub/week44/html/._week44-bs039.html index 09173eafa..39785f947 100644 --- a/doc/pub/week44/html/._week44-bs039.html +++ b/doc/pub/week44/html/._week44-bs039.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,19 +322,43 @@ MathJax.Hub.Config({

     

     

     

    -

    Algorithms for Setting up Decision Trees

    +

    Printing out as text

    -

    Two algorithms stand out in the set up of decision trees:

    -
      -
    1. The CART (Classification And Regression Tree) algorithm for both classification and regression
    2. -
    3. The ID3 algorithm based on the computation of the information gain for classification
    4. -
    -

    We discuss both algorithms with applications here. The popular library -Scikit-Learn uses the CART algorithm. For classification problems -you can use either the gini index or the entropy to split a tree -in two branches. +

    Alternatively, the tree can also be exported in textual format with the function exporttext. +This method doesn’t require the installation of external libraries and is more compact:

    + + +
    +
    +
    +
    +
    +
    from sklearn.datasets import load_iris
    +from sklearn.tree import DecisionTreeClassifier
    +from sklearn.tree import export_text
    +iris = load_iris()
    +decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2)
    +decision_tree = decision_tree.fit(iris.data, iris.target)
    +r = export_text(decision_tree, feature_names=iris['feature_names'])
    +print(r)
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +

    diff --git a/doc/pub/week44/html/._week44-bs040.html b/doc/pub/week44/html/._week44-bs040.html index 7a85c249c..55c8a374f 100644 --- a/doc/pub/week44/html/._week44-bs040.html +++ b/doc/pub/week44/html/._week44-bs040.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,29 +322,17 @@ MathJax.Hub.Config({

     

     

     

    -

    The CART algorithm for Classification

    +

    Algorithms for Setting up Decision Trees

    -

    For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \). -This could be for example a threshold set by a number below a certain circumference of a malign tumor. -

    - -

    How do we find these two quantities? -We search for the pair \( (k,t_k) \) that produces the purest subset using for example the gini factor \( G \). -The cost function it tries to minimize is then -

    -$$ -C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}}, -$$ - -

    where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \) - is the number of instances in the left/right subset -

    - -

    Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets -and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the -\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other -hyperparameters control additional stopping conditions such as the \( min\_samples\_split \), -\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \). +

    Two algorithms stand out in the set up of decision trees:

    +
      +
    1. The CART (Classification And Regression Tree) algorithm for both classification and regression
    2. +
    3. The ID3 algorithm based on the computation of the information gain for classification
    4. +
    +

    We discuss both algorithms with applications here. The popular library +Scikit-Learn uses the CART algorithm. For classification problems +you can use either the gini index or the entropy to split a tree +in two branches.

    @@ -370,7 +360,7 @@ hyperparameters control additional stopping conditions such as the \( min\_sampl

  • 49
  • 50
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs041.html b/doc/pub/week44/html/._week44-bs041.html index 07b2da0b4..323d161e2 100644 --- a/doc/pub/week44/html/._week44-bs041.html +++ b/doc/pub/week44/html/._week44-bs041.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,29 +322,29 @@ MathJax.Hub.Config({

     

     

     

    -

    The CART algorithm for Regression

    +

    The CART algorithm for Classification

    -

    The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the -training set in a way that minimizes say the gini or entropy impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now +

    For classification, the CART algorithm splits the data set in two subsets using a single feature \( k \) and a threshold \( t_k \). +This could be for example a threshold set by a number below a certain circumference of a malign tumor. +

    + +

    How do we find these two quantities? +We search for the pair \( (k,t_k) \) that produces the purest subset using for example the gini factor \( G \). +The cost function it tries to minimize is then

    $$ -C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}. +C(k,t_k) = \frac{m_{\mathrm{left}}}{m}G_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}G_{\mathrm{right}}, $$ -

    Here the MSE for a specific node is defined as

    -$$ -\mathrm{MSE}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}(\overline{y}_{\mathrm{node}}-y_i)^2, -$$ +

    where \( G_{\mathrm{left/right}} \) measures the impurity of the left/right subset and \( m_{\mathrm{left/right}} \) + is the number of instances in the left/right subset +

    -

    with

    -$$ -\overline{y}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}y_i, -$$ - -

    the mean value of all observations in a specific node.

    - -

    Without any regularization, the regression task for decision trees, -just like for classification tasks, is prone to overfitting. +

    Once it has successfully split the training set in two, it splits the subsets using the same logic, then the subsubsets +and so on, recursively. It stops recursing once it reaches the maximum depth (defined by the +\( max\_depth \) hyperparameter), or if it cannot find a split that will reduce impurity. A few other +hyperparameters control additional stopping conditions such as the \( min\_samples\_split \), +\( min\_samples\_leaf \), \( min\_weight\_fraction\_leaf \), and \( max\_leaf\_nodes \).

    @@ -370,7 +372,7 @@ just like for classification tasks, is prone to overfitting.

  • 50
  • 51
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs042.html b/doc/pub/week44/html/._week44-bs042.html index e7b46fa8c..e97085785 100644 --- a/doc/pub/week44/html/._week44-bs042.html +++ b/doc/pub/week44/html/._week44-bs042.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,46 +322,30 @@ MathJax.Hub.Config({

     

     

     

    -

    Computing the Gini index

    +

    The CART algorithm for Regression

    -

    The example we will look at is a classical one in many Machine -Learning applications. Based on various meteorological features, we -have several so-called attributes which decide whether we at the end -will do some outdoor activity like skiing, going for a bike ride etc -etc. The table here contains the feautures outlook, temperature, -humidity and wind. The target or output is whether we ride -(True=1) or whether we do something else that day (False=0). The -attributes for each feature are then sunny, overcast and rain for the -outlook, hot, cold and mild for temperature, high and normal for -humidity and weak and strong for wind. +

    The CART algorithm for regression works is similar to the one for classification except that instead of trying to split the +training set in a way that minimizes say the gini or entropy impurity, it now tries to split the training set in a way that minimizes our well-known mean-squared error (MSE). The cost function is now

    +$$ +C(k,t_k) = \frac{m_{\mathrm{left}}}{m}\mathrm{MSE}_{\mathrm{left}}+ \frac{m_{\mathrm{right}}}{m}\mathrm{MSE}_{\mathrm{right}}. +$$ -

    The table here summarizes the various attributes and

    -
    -
    - - - - - - - - - - - - - - - - - - - - -
    Day Outlook Temperature Humidity Wind Ride
    1 Sunny Hot High Weak 0
    2 Sunny Hot High Strong 1
    3 Overcast Hot High Weak 1
    4 Rain Mild High Weak 1
    5 Rain Cool Normal Weak 1
    6 Rain Cool Normal Strong 0
    7 Overcast Cool Normal Strong 1
    8 Sunny Mild High Weak 0
    9 Sunny Cool Normal Weak 1
    10 Rain Mild Normal Weak 1
    11 Sunny Mild Normal Strong 1
    12 Overcast Mild High Strong 1
    13 Overcast Hot Normal Weak 1
    14 Rain Mild High Strong 0
    -
    -
    +

    Here the MSE for a specific node is defined as

    +$$ +\mathrm{MSE}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}(\overline{y}_{\mathrm{node}}-y_i)^2, +$$ + +

    with

    +$$ +\overline{y}_{\mathrm{node}}=\frac{1}{m_\mathrm{node}}\sum_{i\in \mathrm{node}}y_i, +$$ + +

    the mean value of all observations in a specific node.

    + +

    Without any regularization, the regression task for decision trees, +just like for classification tasks, is prone to overfitting. +

    @@ -386,7 +372,7 @@ humidity and weak and strong for wind.

  • 51
  • 52
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs043.html b/doc/pub/week44/html/._week44-bs043.html index 1488600f2..4072f3b0a 100644 --- a/doc/pub/week44/html/._week44-bs043.html +++ b/doc/pub/week44/html/._week44-bs043.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,97 +322,46 @@ MathJax.Hub.Config({

     

     

     

    -

    Simple Python Code to read in Data and perform Classification

    +

    Computing the Gini index

    +

    The example we will look at is a classical one in many Machine +Learning applications. Based on various meteorological features, we +have several so-called attributes which decide whether we at the end +will do some outdoor activity like skiing, going for a bike ride etc +etc. The table here contains the feautures outlook, temperature, +humidity and wind. The target or output is whether we ride +(True=1) or whether we do something else that day (False=0). The +attributes for each feature are then sunny, overcast and rain for the +outlook, hot, cold and mild for temperature, high and normal for +humidity and weak and strong for wind. +

    - -
    -
    -
    -
    -
    -
    # Common imports
    -import numpy as np
    -import pandas as pd
    -import matplotlib.pyplot as plt
    -from sklearn.tree import DecisionTreeClassifier
    -from sklearn.model_selection import train_test_split
    -from sklearn.tree import export_graphviz
    -from sklearn.preprocessing import StandardScaler, OneHotEncoder
    -from sklearn.compose import ColumnTransformer
    -from IPython.display import Image 
    -from pydot import graph_from_dot_data
    -import os
    -
    -# Where to save the figures and data files
    -PROJECT_ROOT_DIR = "Results"
    -FIGURE_ID = "Results/FigureFiles"
    -DATA_ID = "DataFiles/"
    -
    -if not os.path.exists(PROJECT_ROOT_DIR):
    -    os.mkdir(PROJECT_ROOT_DIR)
    -
    -if not os.path.exists(FIGURE_ID):
    -    os.makedirs(FIGURE_ID)
    -
    -if not os.path.exists(DATA_ID):
    -    os.makedirs(DATA_ID)
    -
    -def image_path(fig_id):
    -    return os.path.join(FIGURE_ID, fig_id)
    -
    -def data_path(dat_id):
    -    return os.path.join(DATA_ID, dat_id)
    -
    -def save_fig(fig_id):
    -    plt.savefig(image_path(fig_id) + ".png", format='png')
    -
    -infile = open(data_path("rideclass.csv"),'r')
    -
    -# Read the experimental data with Pandas
    -from IPython.display import display
    -ridedata = pd.read_csv(infile,names = ('Outlook','Temperature','Humidity','Wind','Ride'))
    -ridedata = pd.DataFrame(ridedata)
    -
    -# Features and targets
    -X = ridedata.loc[:, ridedata.columns != 'Ride'].values
    -y = ridedata.loc[:, ridedata.columns == 'Ride'].values
    -
    -# Create the encoder.
    -encoder = OneHotEncoder(handle_unknown="ignore")
    -# Assume for simplicity all features are categorical.
    -encoder.fit(X)    
    -# Apply the encoder.
    -X = encoder.transform(X)
    -print(X)
    -# Then do a Classification tree
    -tree_clf = DecisionTreeClassifier(max_depth=2)
    -tree_clf.fit(X, y)
    -print("Train set accuracy with Decision Tree: {:.2f}".format(tree_clf.score(X,y)))
    -#transfer to a decision tree graph
    -export_graphviz(
    -    tree_clf,
    -    out_file="DataFiles/ride.dot",
    -    rounded=True,
    -    filled=True
    -)
    -cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'
    -os.system(cmd)
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - +

    The table here summarizes the various attributes and

    +
    +
    + + + + + + + + + + + + + + + + + + + + +
    Day Outlook Temperature Humidity Wind Ride
    1 Sunny Hot High Weak 0
    2 Sunny Hot High Strong 1
    3 Overcast Hot High Weak 1
    4 Rain Mild High Weak 1
    5 Rain Cool Normal Weak 1
    6 Rain Cool Normal Strong 0
    7 Overcast Cool Normal Strong 1
    8 Sunny Mild High Weak 0
    9 Sunny Cool Normal Weak 1
    10 Rain Mild Normal Weak 1
    11 Sunny Mild Normal Strong 1
    12 Overcast Mild High Strong 1
    13 Overcast Hot Normal Weak 1
    14 Rain Mild High Strong 0
    +
    +

    @@ -437,7 +388,7 @@ os.system(cmd)

  • 52
  • 53
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs044.html b/doc/pub/week44/html/._week44-bs044.html index 453606f30..940a2c304 100644 --- a/doc/pub/week44/html/._week44-bs044.html +++ b/doc/pub/week44/html/._week44-bs044.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,15 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Computing the Gini Factor

    - -

    The above functions (gini, entropy and misclassification error) are -important components of the so-called CART algorithm. We will discuss -this algorithm below after we have discussed the information gain -algorithm ID3. -

    - -

    In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.

    +

    Simple Python Code to read in Data and perform Classification

    @@ -337,66 +331,73 @@ algorithm ID3.
    -
    # Split a dataset based on an attribute and an attribute value
    -def test_split(index, value, dataset):
    -	left, right = list(), list()
    -	for row in dataset:
    -		if row[index] < value:
    -			left.append(row)
    -		else:
    -			right.append(row)
    -	return left, right
    - 
    -# Calculate the Gini index for a split dataset
    -def gini_index(groups, classes):
    -	# count all samples at split point
    -	n_instances = float(sum([len(group) for group in groups]))
    -	# sum weighted Gini index for each group
    -	gini = 0.0
    -	for group in groups:
    -		size = float(len(group))
    -		# avoid divide by zero
    -		if size == 0:
    -			continue
    -		score = 0.0
    -		# score the group based on the score for each class
    -		for class_val in classes:
    -			p = [row[-1] for row in group].count(class_val) / size
    -			score += p * p
    -		# weight the group score by its relative size
    -		gini += (1.0 - score) * (size / n_instances)
    -	return gini
    +  
    # Common imports
    +import numpy as np
    +import pandas as pd
    +import matplotlib.pyplot as plt
    +from sklearn.tree import DecisionTreeClassifier
    +from sklearn.model_selection import train_test_split
    +from sklearn.tree import export_graphviz
    +from sklearn.preprocessing import StandardScaler, OneHotEncoder
    +from sklearn.compose import ColumnTransformer
    +from IPython.display import Image 
    +from pydot import graph_from_dot_data
    +import os
     
    -# Select the best split point for a dataset
    -def get_split(dataset):
    -	class_values = list(set(row[-1] for row in dataset))
    -	b_index, b_value, b_score, b_groups = 999, 999, 999, None
    -	for index in range(len(dataset[0])-1):
    -		for row in dataset:
    -			groups = test_split(index, row[index], dataset)
    -			gini = gini_index(groups, class_values)
    -			print('X%d < %.3f Gini=%.3f' % ((index+1), row[index], gini))
    -			if gini < b_score:
    -				b_index, b_value, b_score, b_groups = index, row[index], gini, groups
    -	return {'index':b_index, 'value':b_value, 'groups':b_groups}
    - 
    -dataset = [[0,0,0,0,0],
    -            [0,0,0,1,1],
    -            [1,0,0,0,1],
    -            [2,1,0,0,1],
    -            [2,2,1,0,1],
    -            [2,2,1,1,0],
    -            [1,2,1,1,1],
    -            [0,1,0,0,0],
    -            [0,2,1,0,1],
    -            [2,1,1,0,1],
    -            [0,1,1,1,1],
    -            [1,1,0,1,1],
    -            [1,0,1,0,1],
    -            [2,1,0,1,0]]
    +# Where to save the figures and data files
    +PROJECT_ROOT_DIR = "Results"
    +FIGURE_ID = "Results/FigureFiles"
    +DATA_ID = "DataFiles/"
     
    -split = get_split(dataset)
    -print('Split: [X%d < %.3f]' % ((split['index']+1), split['value']))
    +if not os.path.exists(PROJECT_ROOT_DIR):
    +    os.mkdir(PROJECT_ROOT_DIR)
    +
    +if not os.path.exists(FIGURE_ID):
    +    os.makedirs(FIGURE_ID)
    +
    +if not os.path.exists(DATA_ID):
    +    os.makedirs(DATA_ID)
    +
    +def image_path(fig_id):
    +    return os.path.join(FIGURE_ID, fig_id)
    +
    +def data_path(dat_id):
    +    return os.path.join(DATA_ID, dat_id)
    +
    +def save_fig(fig_id):
    +    plt.savefig(image_path(fig_id) + ".png", format='png')
    +
    +infile = open(data_path("rideclass.csv"),'r')
    +
    +# Read the experimental data with Pandas
    +from IPython.display import display
    +ridedata = pd.read_csv(infile,names = ('Outlook','Temperature','Humidity','Wind','Ride'))
    +ridedata = pd.DataFrame(ridedata)
    +
    +# Features and targets
    +X = ridedata.loc[:, ridedata.columns != 'Ride'].values
    +y = ridedata.loc[:, ridedata.columns == 'Ride'].values
    +
    +# Create the encoder.
    +encoder = OneHotEncoder(handle_unknown="ignore")
    +# Assume for simplicity all features are categorical.
    +encoder.fit(X)    
    +# Apply the encoder.
    +X = encoder.transform(X)
    +print(X)
    +# Then do a Classification tree
    +tree_clf = DecisionTreeClassifier(max_depth=2)
    +tree_clf.fit(X, y)
    +print("Train set accuracy with Decision Tree: {:.2f}".format(tree_clf.score(X,y)))
    +#transfer to a decision tree graph
    +export_graphviz(
    +    tree_clf,
    +    out_file="DataFiles/ride.dot",
    +    rounded=True,
    +    filled=True
    +)
    +cmd = 'dot -Tpng DataFiles/cancer.dot -o DataFiles/cancer.png'
    +os.system(cmd)
     
    @@ -438,7 +439,7 @@ split = get_split(dataset)
  • 53
  • 54
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs045.html b/doc/pub/week44/html/._week44-bs045.html index 9f469058a..77ef6b981 100644 --- a/doc/pub/week44/html/._week44-bs045.html +++ b/doc/pub/week44/html/._week44-bs045.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,37 +322,98 @@ MathJax.Hub.Config({

     

     

     

    -

    Entropy and the ID3 algorithm

    +

    Computing the Gini Factor

    -

    The ID3 algorithm learns decision trees by constructing -them in a top down way, beginning with the question which attribute should be tested at the root of the tree? +

    The above functions (gini, entropy and misclassification error) are +important components of the so-called CART algorithm. We will discuss +this algorithm below after we have discussed the information gain +algorithm ID3.

    -
      -
    1. Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.
    2. -
    3. The best attribute is selected and used as the test at the root node of the tree.
    4. -
    5. A descendant of the root node is then created for each possible value of this attribute.
    6. -
    7. Training examples are sorted to the appropriate descendant node.
    8. -
    9. The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.
    10. -
    11. This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.
    12. -
    -

    The ID3 algorithm selects which attribute to test at each node in the -tree. -

    +

    In the example here we have converted all our attributes into numerical values \( 0,1,2 \) etc.

    -

    We would like to select the attribute that is most useful for classifying -examples. -

    -

    What is a good quantitative measure of the worth of an attribute?

    + +
    +
    +
    +
    +
    +
    # Split a dataset based on an attribute and an attribute value
    +def test_split(index, value, dataset):
    +	left, right = list(), list()
    +	for row in dataset:
    +		if row[index] < value:
    +			left.append(row)
    +		else:
    +			right.append(row)
    +	return left, right
    + 
    +# Calculate the Gini index for a split dataset
    +def gini_index(groups, classes):
    +	# count all samples at split point
    +	n_instances = float(sum([len(group) for group in groups]))
    +	# sum weighted Gini index for each group
    +	gini = 0.0
    +	for group in groups:
    +		size = float(len(group))
    +		# avoid divide by zero
    +		if size == 0:
    +			continue
    +		score = 0.0
    +		# score the group based on the score for each class
    +		for class_val in classes:
    +			p = [row[-1] for row in group].count(class_val) / size
    +			score += p * p
    +		# weight the group score by its relative size
    +		gini += (1.0 - score) * (size / n_instances)
    +	return gini
     
    -

    Information gain measures how well a given attribute separates the -training examples according to their target classification. -

    +# Select the best split point for a dataset +def get_split(dataset): + class_values = list(set(row[-1] for row in dataset)) + b_index, b_value, b_score, b_groups = 999, 999, 999, None + for index in range(len(dataset[0])-1): + for row in dataset: + groups = test_split(index, row[index], dataset) + gini = gini_index(groups, class_values) + print('X%d < %.3f Gini=%.3f' % ((index+1), row[index], gini)) + if gini < b_score: + b_index, b_value, b_score, b_groups = index, row[index], gini, groups + return {'index':b_index, 'value':b_value, 'groups':b_groups} + +dataset = [[0,0,0,0,0], + [0,0,0,1,1], + [1,0,0,0,1], + [2,1,0,0,1], + [2,2,1,0,1], + [2,2,1,1,0], + [1,2,1,1,1], + [0,1,0,0,0], + [0,2,1,0,1], + [2,1,1,0,1], + [0,1,1,1,1], + [1,1,0,1,1], + [1,0,1,0,1], + [2,1,0,1,0]] + +split = get_split(dataset) +print('Split: [X%d < %.3f]' % ((split['index']+1), split['value'])) +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    -

    The ID3 algorithm uses this information gain measure to select among the candidate -attributes at each step while growing the tree. -

    @@ -377,7 +440,7 @@ attributes at each step while growing the tree.

  • 54
  • 55
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs046.html b/doc/pub/week44/html/._week44-bs046.html index 003526893..267575516 100644 --- a/doc/pub/week44/html/._week44-bs046.html +++ b/doc/pub/week44/html/._week44-bs046.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,70 +322,37 @@ MathJax.Hub.Config({

     

     

     

    -

    Cancer Data again now with Decision Trees and other Methods

    +

    Entropy and the ID3 algorithm

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

    The ID3 algorithm learns decision trees by constructing +them in a top down way, beginning with the question which attribute should be tested at the root of the tree? +

    -# Load the data -cancer = load_breast_cancer() +
      +
    1. Each instance attribute is evaluated using a statistical test to determine how well it alone classifies the training examples.
    2. +
    3. The best attribute is selected and used as the test at the root node of the tree.
    4. +
    5. A descendant of the root node is then created for each possible value of this attribute.
    6. +
    7. Training examples are sorted to the appropriate descendant node.
    8. +
    9. The entire process is then repeated using the training examples associated with each descendant node to select the best attribute to test at that point in the tree.
    10. +
    11. This forms a greedy search for an acceptable decision tree, in which the algorithm never backtracks to reconsider earlier choices.
    12. +
    +

    The ID3 algorithm selects which attribute to test at each node in the +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))) -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

    We would like to select the attribute that is most useful for classifying +examples. +

    +

    What is a good quantitative measure of the worth of an attribute?

    + +

    Information gain measures how well a given attribute separates the +training examples according to their target classification. +

    + +

    The ID3 algorithm uses this information gain measure to select among the candidate +attributes at each step while growing the tree. +

    @@ -410,7 +379,7 @@ deep_tree_clf.fit(X_train_scaled, y_train)

  • 55
  • 56
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs047.html b/doc/pub/week44/html/._week44-bs047.html index ba48b94eb..c28229dc5 100644 --- a/doc/pub/week44/html/._week44-bs047.html +++ b/doc/pub/week44/html/._week44-bs047.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Another example, the moons again

    +

    Cancer Data again now with Decision Trees and other Methods

    @@ -328,70 +330,47 @@ MathJax.Hub.Config({
    -
    from __future__ import division, print_function, unicode_literals
    -
    -# Common imports
    +  
    import matplotlib.pyplot as plt
     import numpy as np
    -import os
    -
    -# to make this notebook's output stable across runs
    -np.random.seed(42)
    -
    -# To plot pretty figures
    -import matplotlib
    -import matplotlib.pyplot as plt
    -from matplotlib.colors import ListedColormap
    -plt.rcParams['axes.labelsize'] = 14
    -plt.rcParams['xtick.labelsize'] = 12
    -plt.rcParams['ytick.labelsize'] = 12
    -
    -
    +from sklearn.model_selection import  train_test_split 
    +from sklearn.datasets import load_breast_cancer
     from sklearn.svm import SVC
    -from sklearn import datasets
    +from sklearn.linear_model import LogisticRegression
     from sklearn.tree import DecisionTreeClassifier
    -from sklearn.datasets import make_moons
    -from sklearn.tree import export_graphviz
     
    -Xm, ym = make_moons(n_samples=100, noise=0.25, random_state=53)
    +# Load the data
    +cancer = load_breast_cancer()
     
    -deep_tree_clf1 = DecisionTreeClassifier(random_state=42)
    -deep_tree_clf2 = DecisionTreeClassifier(min_samples_leaf=4, random_state=42)
    -deep_tree_clf1.fit(Xm, ym)
    -deep_tree_clf2.fit(Xm, ym)
    -
    -
    -def plot_decision_boundary(clf, X, y, axes=[0, 7.5, 0, 3], iris=True, legend=False, plot_training=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 not iris:
    -        custom_cmap2 = ListedColormap(['#7d7d58','#4c4c7f','#507d50'])
    -        plt.contour(x1, x2, y_pred, cmap=custom_cmap2, alpha=0.8)
    -    if plot_training:
    -        plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo", label="Iris-Setosa")
    -        plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs", label="Iris-Versicolor")
    -        plt.plot(X[:, 0][y==2], X[:, 1][y==2], "g^", label="Iris-Virginica")
    -        plt.axis(axes)
    -    if iris:
    -        plt.xlabel("Petal length", fontsize=14)
    -        plt.ylabel("Petal width", fontsize=14)
    -    else:
    -        plt.xlabel(r"$x_1$", fontsize=18)
    -        plt.ylabel(r"$x_2$", fontsize=18, rotation=0)
    -    if legend:
    -        plt.legend(loc="lower right", fontsize=14)
    -plt.figure(figsize=(11, 4))
    -plt.subplot(121)
    -plot_decision_boundary(deep_tree_clf1, Xm, ym, axes=[-1.5, 2.5, -1, 1.5], iris=False)
    -plt.title("No restrictions", fontsize=16)
    -plt.subplot(122)
    -plot_decision_boundary(deep_tree_clf2, Xm, ym, axes=[-1.5, 2.5, -1, 1.5], iris=False)
    -plt.title("min_samples_leaf = {}".format(deep_tree_clf2.min_samples_leaf), fontsize=14)
    -plt.show()
    +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)))
     
    @@ -433,7 +412,7 @@ plt.show()
  • 56
  • 57
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs048.html b/doc/pub/week44/html/._week44-bs048.html index 0f6f4dd6b..447786f32 100644 --- a/doc/pub/week44/html/._week44-bs048.html +++ b/doc/pub/week44/html/._week44-bs048.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Playing around with regions

    +

    Another example, the moons again

    @@ -328,25 +330,69 @@ MathJax.Hub.Config({
    -
    np.random.seed(6)
    -Xs = np.random.rand(100, 2) - 0.5
    -ys = (Xs[:, 0] > 0).astype(np.float32) * 2
    +  
    from __future__ import division, print_function, unicode_literals
     
    -angle = np.pi/4
    -rotation_matrix = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
    -Xsr = Xs.dot(rotation_matrix)
    +# Common imports
    +import numpy as np
    +import os
     
    -tree_clf_s = DecisionTreeClassifier(random_state=42)
    -tree_clf_s.fit(Xs, ys)
    -tree_clf_sr = DecisionTreeClassifier(random_state=42)
    -tree_clf_sr.fit(Xsr, ys)
    +# to make this notebook's output stable across runs
    +np.random.seed(42)
     
    +# To plot pretty figures
    +import matplotlib
    +import matplotlib.pyplot as plt
    +from matplotlib.colors import ListedColormap
    +plt.rcParams['axes.labelsize'] = 14
    +plt.rcParams['xtick.labelsize'] = 12
    +plt.rcParams['ytick.labelsize'] = 12
    +
    +
    +from sklearn.svm import SVC
    +from sklearn import datasets
    +from sklearn.tree import DecisionTreeClassifier
    +from sklearn.datasets import make_moons
    +from sklearn.tree import export_graphviz
    +
    +Xm, ym = make_moons(n_samples=100, noise=0.25, random_state=53)
    +
    +deep_tree_clf1 = DecisionTreeClassifier(random_state=42)
    +deep_tree_clf2 = DecisionTreeClassifier(min_samples_leaf=4, random_state=42)
    +deep_tree_clf1.fit(Xm, ym)
    +deep_tree_clf2.fit(Xm, ym)
    +
    +
    +def plot_decision_boundary(clf, X, y, axes=[0, 7.5, 0, 3], iris=True, legend=False, plot_training=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 not iris:
    +        custom_cmap2 = ListedColormap(['#7d7d58','#4c4c7f','#507d50'])
    +        plt.contour(x1, x2, y_pred, cmap=custom_cmap2, alpha=0.8)
    +    if plot_training:
    +        plt.plot(X[:, 0][y==0], X[:, 1][y==0], "yo", label="Iris-Setosa")
    +        plt.plot(X[:, 0][y==1], X[:, 1][y==1], "bs", label="Iris-Versicolor")
    +        plt.plot(X[:, 0][y==2], X[:, 1][y==2], "g^", label="Iris-Virginica")
    +        plt.axis(axes)
    +    if iris:
    +        plt.xlabel("Petal length", fontsize=14)
    +        plt.ylabel("Petal width", fontsize=14)
    +    else:
    +        plt.xlabel(r"$x_1$", fontsize=18)
    +        plt.ylabel(r"$x_2$", fontsize=18, rotation=0)
    +    if legend:
    +        plt.legend(loc="lower right", fontsize=14)
     plt.figure(figsize=(11, 4))
     plt.subplot(121)
    -plot_decision_boundary(tree_clf_s, Xs, ys, axes=[-0.7, 0.7, -0.7, 0.7], iris=False)
    +plot_decision_boundary(deep_tree_clf1, Xm, ym, axes=[-1.5, 2.5, -1, 1.5], iris=False)
    +plt.title("No restrictions", fontsize=16)
     plt.subplot(122)
    -plot_decision_boundary(tree_clf_sr, Xsr, ys, axes=[-0.7, 0.7, -0.7, 0.7], iris=False)
    -
    +plot_decision_boundary(deep_tree_clf2, Xm, ym, axes=[-1.5, 2.5, -1, 1.5], iris=False)
    +plt.title("min_samples_leaf = {}".format(deep_tree_clf2.min_samples_leaf), fontsize=14)
     plt.show()
     
    @@ -389,7 +435,7 @@ plt.show()
  • 57
  • 58
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs049.html b/doc/pub/week44/html/._week44-bs049.html index afd4f6caf..c0813f521 100644 --- a/doc/pub/week44/html/._week44-bs049.html +++ b/doc/pub/week44/html/._week44-bs049.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Regression trees

    +

    Playing around with regions

    @@ -328,35 +330,26 @@ MathJax.Hub.Config({
    -
    # Quadratic training set + noise
    -np.random.seed(42)
    -m = 200
    -X = np.random.rand(m, 1)
    -y = 4 * (X - 0.5) ** 2
    -y = y + np.random.randn(m, 1) / 10
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    - -
    -
    -
    -
    -
    -
    from sklearn.tree import DecisionTreeRegressor
    +  
    np.random.seed(6)
    +Xs = np.random.rand(100, 2) - 0.5
    +ys = (Xs[:, 0] > 0).astype(np.float32) * 2
     
    -tree_reg = DecisionTreeRegressor(max_depth=2, random_state=42)
    -tree_reg.fit(X, y)
    +angle = np.pi/4
    +rotation_matrix = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
    +Xsr = Xs.dot(rotation_matrix)
    +
    +tree_clf_s = DecisionTreeClassifier(random_state=42)
    +tree_clf_s.fit(Xs, ys)
    +tree_clf_sr = DecisionTreeClassifier(random_state=42)
    +tree_clf_sr.fit(Xsr, ys)
    +
    +plt.figure(figsize=(11, 4))
    +plt.subplot(121)
    +plot_decision_boundary(tree_clf_s, Xs, ys, axes=[-0.7, 0.7, -0.7, 0.7], iris=False)
    +plt.subplot(122)
    +plot_decision_boundary(tree_clf_sr, Xsr, ys, axes=[-0.7, 0.7, -0.7, 0.7], iris=False)
    +
    +plt.show()
     
    @@ -398,7 +391,7 @@ tree_reg.fit(X, y)
  • 58
  • 59
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs050.html b/doc/pub/week44/html/._week44-bs050.html index 6bfbbb71f..66e562fda 100644 --- a/doc/pub/week44/html/._week44-bs050.html +++ b/doc/pub/week44/html/._week44-bs050.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Final regressor code

    +

    Regression trees

    @@ -328,44 +330,12 @@ MathJax.Hub.Config({
    -
    from sklearn.tree import DecisionTreeRegressor
    -
    -tree_reg1 = DecisionTreeRegressor(random_state=42, max_depth=2)
    -tree_reg2 = DecisionTreeRegressor(random_state=42, max_depth=3)
    -tree_reg1.fit(X, y)
    -tree_reg2.fit(X, y)
    -
    -def plot_regression_predictions(tree_reg, X, y, axes=[0, 1, -0.2, 1], ylabel="$y$"):
    -    x1 = np.linspace(axes[0], axes[1], 500).reshape(-1, 1)
    -    y_pred = tree_reg.predict(x1)
    -    plt.axis(axes)
    -    plt.xlabel("$x_1$", fontsize=18)
    -    if ylabel:
    -        plt.ylabel(ylabel, fontsize=18, rotation=0)
    -    plt.plot(X, y, "b.")
    -    plt.plot(x1, y_pred, "r.-", linewidth=2, label=r"$\hat{y}$")
    -
    -plt.figure(figsize=(11, 4))
    -plt.subplot(121)
    -plot_regression_predictions(tree_reg1, X, y)
    -for split, style in ((0.1973, "k-"), (0.0917, "k--"), (0.7718, "k--")):
    -    plt.plot([split, split], [-0.2, 1], style, linewidth=2)
    -plt.text(0.21, 0.65, "Depth=0", fontsize=15)
    -plt.text(0.01, 0.2, "Depth=1", fontsize=13)
    -plt.text(0.65, 0.8, "Depth=1", fontsize=13)
    -plt.legend(loc="upper center", fontsize=18)
    -plt.title("max_depth=2", fontsize=14)
    -
    -plt.subplot(122)
    -plot_regression_predictions(tree_reg2, X, y, ylabel=None)
    -for split, style in ((0.1973, "k-"), (0.0917, "k--"), (0.7718, "k--")):
    -    plt.plot([split, split], [-0.2, 1], style, linewidth=2)
    -for split in (0.0458, 0.1298, 0.2873, 0.9040):
    -    plt.plot([split, split], [-0.2, 1], "k:", linewidth=1)
    -plt.text(0.3, 0.5, "Depth=2", fontsize=13)
    -plt.title("max_depth=3", fontsize=14)
    -
    -plt.show()
    +  
    # Quadratic training set + noise
    +np.random.seed(42)
    +m = 200
    +X = np.random.rand(m, 1)
    +y = 4 * (X - 0.5) ** 2
    +y = y + np.random.randn(m, 1) / 10
     
    @@ -385,34 +355,10 @@ plt.show()
    -
    tree_reg1 = DecisionTreeRegressor(random_state=42)
    -tree_reg2 = DecisionTreeRegressor(random_state=42, min_samples_leaf=10)
    -tree_reg1.fit(X, y)
    -tree_reg2.fit(X, y)
    +  
    from sklearn.tree import DecisionTreeRegressor
     
    -x1 = np.linspace(0, 1, 500).reshape(-1, 1)
    -y_pred1 = tree_reg1.predict(x1)
    -y_pred2 = tree_reg2.predict(x1)
    -
    -plt.figure(figsize=(11, 4))
    -
    -plt.subplot(121)
    -plt.plot(X, y, "b.")
    -plt.plot(x1, y_pred1, "r.-", linewidth=2, label=r"$\hat{y}$")
    -plt.axis([0, 1, -0.2, 1.1])
    -plt.xlabel("$x_1$", fontsize=18)
    -plt.ylabel("$y$", fontsize=18, rotation=0)
    -plt.legend(loc="upper center", fontsize=18)
    -plt.title("No restrictions", fontsize=14)
    -
    -plt.subplot(122)
    -plt.plot(X, y, "b.")
    -plt.plot(x1, y_pred2, "r.-", linewidth=2, label=r"$\hat{y}$")
    -plt.axis([0, 1, -0.2, 1.1])
    -plt.xlabel("$x_1$", fontsize=18)
    -plt.title("min_samples_leaf={}".format(tree_reg2.min_samples_leaf), fontsize=14)
    -
    -plt.show()
    +tree_reg = DecisionTreeRegressor(max_depth=2, random_state=42)
    +tree_reg.fit(X, y)
     
    @@ -454,7 +400,7 @@ plt.show()
  • 59
  • 60
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs051.html b/doc/pub/week44/html/._week44-bs051.html index cea2d1342..eff7106cf 100644 --- a/doc/pub/week44/html/._week44-bs051.html +++ b/doc/pub/week44/html/._week44-bs051.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,17 +322,115 @@ MathJax.Hub.Config({

     

     

     

    -

    Pros and cons of trees, pros

    +

    Final regressor code

    + + +
    +
    +
    +
    +
    +
    from sklearn.tree import DecisionTreeRegressor
    +
    +tree_reg1 = DecisionTreeRegressor(random_state=42, max_depth=2)
    +tree_reg2 = DecisionTreeRegressor(random_state=42, max_depth=3)
    +tree_reg1.fit(X, y)
    +tree_reg2.fit(X, y)
    +
    +def plot_regression_predictions(tree_reg, X, y, axes=[0, 1, -0.2, 1], ylabel="$y$"):
    +    x1 = np.linspace(axes[0], axes[1], 500).reshape(-1, 1)
    +    y_pred = tree_reg.predict(x1)
    +    plt.axis(axes)
    +    plt.xlabel("$x_1$", fontsize=18)
    +    if ylabel:
    +        plt.ylabel(ylabel, fontsize=18, rotation=0)
    +    plt.plot(X, y, "b.")
    +    plt.plot(x1, y_pred, "r.-", linewidth=2, label=r"$\hat{y}$")
    +
    +plt.figure(figsize=(11, 4))
    +plt.subplot(121)
    +plot_regression_predictions(tree_reg1, X, y)
    +for split, style in ((0.1973, "k-"), (0.0917, "k--"), (0.7718, "k--")):
    +    plt.plot([split, split], [-0.2, 1], style, linewidth=2)
    +plt.text(0.21, 0.65, "Depth=0", fontsize=15)
    +plt.text(0.01, 0.2, "Depth=1", fontsize=13)
    +plt.text(0.65, 0.8, "Depth=1", fontsize=13)
    +plt.legend(loc="upper center", fontsize=18)
    +plt.title("max_depth=2", fontsize=14)
    +
    +plt.subplot(122)
    +plot_regression_predictions(tree_reg2, X, y, ylabel=None)
    +for split, style in ((0.1973, "k-"), (0.0917, "k--"), (0.7718, "k--")):
    +    plt.plot([split, split], [-0.2, 1], style, linewidth=2)
    +for split in (0.0458, 0.1298, 0.2873, 0.9040):
    +    plt.plot([split, split], [-0.2, 1], "k:", linewidth=1)
    +plt.text(0.3, 0.5, "Depth=2", fontsize=13)
    +plt.title("max_depth=3", fontsize=14)
    +
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    tree_reg1 = DecisionTreeRegressor(random_state=42)
    +tree_reg2 = DecisionTreeRegressor(random_state=42, min_samples_leaf=10)
    +tree_reg1.fit(X, y)
    +tree_reg2.fit(X, y)
    +
    +x1 = np.linspace(0, 1, 500).reshape(-1, 1)
    +y_pred1 = tree_reg1.predict(x1)
    +y_pred2 = tree_reg2.predict(x1)
    +
    +plt.figure(figsize=(11, 4))
    +
    +plt.subplot(121)
    +plt.plot(X, y, "b.")
    +plt.plot(x1, y_pred1, "r.-", linewidth=2, label=r"$\hat{y}$")
    +plt.axis([0, 1, -0.2, 1.1])
    +plt.xlabel("$x_1$", fontsize=18)
    +plt.ylabel("$y$", fontsize=18, rotation=0)
    +plt.legend(loc="upper center", fontsize=18)
    +plt.title("No restrictions", fontsize=14)
    +
    +plt.subplot(122)
    +plt.plot(X, y, "b.")
    +plt.plot(x1, y_pred2, "r.-", linewidth=2, label=r"$\hat{y}$")
    +plt.axis([0, 1, -0.2, 1.1])
    +plt.xlabel("$x_1$", fontsize=18)
    +plt.title("min_samples_leaf={}".format(tree_reg2.min_samples_leaf), fontsize=14)
    +
    +plt.show()
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + -
      -
    • 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)
    • -

      @@ -356,7 +456,7 @@ MathJax.Hub.Config({
    • 60
    • 61
    • ...
    • -
    • 62
    • +
    • 63
    • »
    diff --git a/doc/pub/week44/html/._week44-bs052.html b/doc/pub/week44/html/._week44-bs052.html index 534e10aab..b73e7e220 100644 --- a/doc/pub/week44/html/._week44-bs052.html +++ b/doc/pub/week44/html/._week44-bs052.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,22 +322,17 @@ MathJax.Hub.Config({

     

     

     

    -

    Disadvantages

    +

    Pros and cons of trees, pros

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

    However, by aggregating many decision trees, using methods like -bagging, random forests, and boosting, the predictive performance of -trees can be substantially improved. -

    -

      @@ -360,6 +357,8 @@ trees can be substantially improved.
    • 60
    • 61
    • 62
    • +
    • ...
    • +
    • 63
    • »
    diff --git a/doc/pub/week44/html/._week44-bs053.html b/doc/pub/week44/html/._week44-bs053.html index 10ab2a99f..8a5cc5c2a 100644 --- a/doc/pub/week44/html/._week44-bs053.html +++ b/doc/pub/week44/html/._week44-bs053.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,29 +322,22 @@ MathJax.Hub.Config({

     

     

     

    -

    Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods

    +

    Disadvantages

    -

    As stated above and seen in many of the examples discussed here about -a single decision tree, we often end up overfitting our training -data. This normally means that we have a high variance. Can we reduce -the variance of a statistical learning method? +

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

    -

    This leads us to a set of different methods that can combine different -machine learning algorithms or just use one of them to construct -forests and jungles of trees, homogeneous ones or heterogenous -ones. These methods are recognized by different names which we will -try to explain here. These are -

    - -
      -
    1. Voting classifiers
    2. -
    3. Bagging and Pasting
    4. -
    5. Random forests
    6. -
    7. Boosting methods, from adaptive to Extreme Gradient Boosting (XGBoost)
    8. -
    -

    We discuss these methods here.

    -

      @@ -366,6 +361,7 @@ try to explain here. These are
    • 60
    • 61
    • 62
    • +
    • 63
    • »
    diff --git a/doc/pub/week44/html/._week44-bs054.html b/doc/pub/week44/html/._week44-bs054.html index cae439611..d700759d6 100644 --- a/doc/pub/week44/html/._week44-bs054.html +++ b/doc/pub/week44/html/._week44-bs054.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,13 +322,28 @@ MathJax.Hub.Config({

     

     

     

    -

    An Overview of Ensemble Methods

    +

    Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods

    -

    -
    -

    -
    -

    +

    As stated above and seen in many of the examples discussed here about +a single decision tree, we often end up overfitting our training +data. This normally means that we have a high variance. Can we reduce +the variance of a statistical learning method? +

    + +

    This leads us to a set of different methods that can combine different +machine learning algorithms or just use one of them to construct +forests and jungles of trees, homogeneous ones or heterogenous +ones. These methods are recognized by different names which we will +try to explain here. These are +

    + +
      +
    1. Voting classifiers
    2. +
    3. Bagging and Pasting
    4. +
    5. Random forests
    6. +
    7. Boosting methods, from adaptive to Extreme Gradient Boosting (XGBoost)
    8. +
    +

    We discuss these methods here.

    @@ -350,6 +367,7 @@ MathJax.Hub.Config({

  • 60
  • 61
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs055.html b/doc/pub/week44/html/._week44-bs055.html index 5a062eefd..6597f32ab 100644 --- a/doc/pub/week44/html/._week44-bs055.html +++ b/doc/pub/week44/html/._week44-bs055.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,21 +322,13 @@ MathJax.Hub.Config({

     

     

     

    -

    Bagging

    +

    An Overview of Ensemble Methods

    -

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

    +

    +
    +

    +
    +

    @@ -357,6 +351,7 @@ learning method.

  • 60
  • 61
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs056.html b/doc/pub/week44/html/._week44-bs056.html index 0838afd79..b5e1697f2 100644 --- a/doc/pub/week44/html/._week44-bs056.html +++ b/doc/pub/week44/html/._week44-bs056.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,30 +322,20 @@ MathJax.Hub.Config({

     

     

     

    -

    More bagging

    +

    Bagging

    -

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

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

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

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

  • 60
  • 61
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs057.html b/doc/pub/week44/html/._week44-bs057.html index d1541b8ab..4becb9352 100644 --- a/doc/pub/week44/html/._week44-bs057.html +++ b/doc/pub/week44/html/._week44-bs057.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,42 +322,31 @@ MathJax.Hub.Config({

     

     

     

    -

    Simple Voting Example, head or tail

    +

    More bagging

    - -
    -
    -
    -
    -
    -
    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])
    -save_fig("votingsimple")
    -plt.show()
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
    +

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

    @@ -376,6 +367,7 @@ plt.show()

  • 60
  • 61
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs058.html b/doc/pub/week44/html/._week44-bs058.html index 30559a1c7..f6b8f776c 100644 --- a/doc/pub/week44/html/._week44-bs058.html +++ b/doc/pub/week44/html/._week44-bs058.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Using the Voting Classifier

    +

    Simple Voting Example, head or tail

    @@ -328,49 +330,19 @@ MathJax.Hub.Config({
    -
    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(solver="liblinear", random_state=42)
    -rnd_clf = RandomForestClassifier(n_estimators=10, random_state=42)
    -svm_clf = SVC(gamma="auto", 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(solver="liblinear", random_state=42)
    -rnd_clf = RandomForestClassifier(n_estimators=10, random_state=42)
    -svm_clf = SVC(gamma="auto", 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))
    +  
    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])
    +save_fig("votingsimple")
    +plt.show()
     
    @@ -405,6 +377,7 @@ voting_clf.fit(X_train, y_train)
  • 60
  • 61
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs059.html b/doc/pub/week44/html/._week44-bs059.html index 72329f117..8dab5b883 100644 --- a/doc/pub/week44/html/._week44-bs059.html +++ b/doc/pub/week44/html/._week44-bs059.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,8 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Please, not the moons again! Voting and Bagging

    - +

    Using the Voting Classifier

    @@ -334,91 +335,39 @@ MathJax.Hub.Config({ 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) +log_clf = LogisticRegression(solver="liblinear", random_state=42) +rnd_clf = RandomForestClassifier(n_estimators=10, random_state=42) +svm_clf = SVC(gamma="auto", 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
    +
    +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)
    +
    +log_clf = LogisticRegression(solver="liblinear", random_state=42)
    +rnd_clf = RandomForestClassifier(n_estimators=10, random_state=42)
    +svm_clf = SVC(gamma="auto", 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
    +
    +from sklearn.metrics import accuracy_score
     
     for clf in (log_clf, rnd_clf, svm_clf, voting_clf):
         clf.fit(X_train, y_train)
    @@ -457,6 +406,7 @@ voting_clf.fit(X_train, y_train)
       
  • 60
  • 61
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/._week44-bs060.html b/doc/pub/week44/html/._week44-bs060.html index 127c312d3..ce61f5338 100644 --- a/doc/pub/week44/html/._week44-bs060.html +++ b/doc/pub/week44/html/._week44-bs060.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -320,7 +322,7 @@ MathJax.Hub.Config({

     

     

     

    -

    Bagging Examples

    +

    Please, not the moons again! Voting and Bagging

    @@ -329,14 +331,24 @@ MathJax.Hub.Config({
    -
    from sklearn.ensemble import BaggingClassifier
    -from sklearn.tree import DecisionTreeClassifier
    +  
    from sklearn.model_selection import train_test_split
    +from sklearn.datasets import make_moons
     
    -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)
    +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)
     
    @@ -357,76 +369,63 @@ y_pred = bag_clf
    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)
    -save_fig("baggingtree")
    -plt.show()
    +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))
     
    @@ -459,6 +458,7 @@ plt.show()
  • 60
  • 61
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/week44-bs.html b/doc/pub/week44/html/week44-bs.html index c4db98304..a503062e6 100644 --- a/doc/pub/week44/html/week44-bs.html +++ b/doc/pub/week44/html/week44-bs.html @@ -37,6 +37,7 @@ doconce format html week44.do.txt --html_style=bootstrap --pygments_html_style=d
  • Overview of week 44
  • -
  • Thursday, Principal Component Analysis
  • -
  • A kind of Bird's view on PCA
  • -
  • Thursday: Clustering and Unsupervised Learning
  • -
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • -
  • The \( k \)-means Algorithm
  • -
  • Basic Math of the \( k \)-means Algorithm
  • -
  • Within Cluster Point Scatter
  • -
  • More Details
  • -
  • Total Cluster Variance
  • -
  • The \( k \)-means Clustering Algorithm
  • -
  • Summarizing
  • -
  • Writing our own Code, the Data Set
  • -
  • Implementing the \( k \)-means Algorithm
  • -
  • Plotting
  • -
  • Continuing
  • -
  • Wrapping it up
  • -
  • Decision trees, overarching aims
  • -
  • Basics of a tree
  • -
  • A Sketch of a Tree, Regression problem
  • -
  • A Sketch of a Tree, Classification problem
  • -
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • -
  • General Features
  • -
  • How do we set it up?
  • -
  • Decision trees and Regression
  • -
  • Building a tree, regression
  • -
  • A top-down approach, recursive binary splitting
  • -
  • Making a tree
  • -
  • Pruning the tree
  • -
  • Cost complexity pruning
  • -
  • Schematic Regression Procedure
  • -
  • A Classification Tree
  • -
  • Growing a classification tree
  • -
  • Classification tree, how to split nodes
  • -
  • Visualizing the Tree, Classification
  • -
  • Visualizing the Tree, The Moons
  • -
  • Other ways of visualizing the trees
  • -
  • Printing out as text
  • -
  • Algorithms for Setting up Decision Trees
  • -
  • The CART algorithm for Classification
  • -
  • The CART algorithm for Regression
  • -
  • Computing the Gini index
  • -
  • Simple Python Code to read in Data and perform Classification
  • -
  • Computing the Gini Factor
  • -
  • Entropy and the ID3 algorithm
  • -
  • Cancer Data again now with Decision Trees and other Methods
  • -
  • Another example, the moons again
  • -
  • Playing around with regions
  • -
  • Regression trees
  • -
  • Final regressor code
  • -
  • Pros and cons of trees, pros
  • -
  • Disadvantages
  • -
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • -
  • An Overview of Ensemble Methods
  • -
  • Bagging
  • -
  • More bagging
  • -
  • Simple Voting Example, head or tail
  • -
  • Using the Voting Classifier
  • -
  • Please, not the moons again! Voting and Bagging
  • -
  • Bagging Examples
  • -
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • +
  • Digression First
  • +
  • Thursday, Principal Component Analysis
  • +
  • A kind of Bird's view on PCA
  • +
  • Thursday: Clustering and Unsupervised Learning
  • +
  • Basic Idea of the \( k \)-means Clustering Algorithm
  • +
  • The \( k \)-means Algorithm
  • +
  • Basic Math of the \( k \)-means Algorithm
  • +
  • Within Cluster Point Scatter
  • +
  • More Details
  • +
  • Total Cluster Variance
  • +
  • The \( k \)-means Clustering Algorithm
  • +
  • Summarizing
  • +
  • Writing our own Code, the Data Set
  • +
  • Implementing the \( k \)-means Algorithm
  • +
  • Plotting
  • +
  • Continuing
  • +
  • Wrapping it up
  • +
  • Decision trees, overarching aims
  • +
  • Basics of a tree
  • +
  • A Sketch of a Tree, Regression problem
  • +
  • A Sketch of a Tree, Classification problem
  • +
  • A typical Decision Tree with its pertinent Jargon, Classification Problem
  • +
  • General Features
  • +
  • How do we set it up?
  • +
  • Decision trees and Regression
  • +
  • Building a tree, regression
  • +
  • A top-down approach, recursive binary splitting
  • +
  • Making a tree
  • +
  • Pruning the tree
  • +
  • Cost complexity pruning
  • +
  • Schematic Regression Procedure
  • +
  • A Classification Tree
  • +
  • Growing a classification tree
  • +
  • Classification tree, how to split nodes
  • +
  • Visualizing the Tree, Classification
  • +
  • Visualizing the Tree, The Moons
  • +
  • Other ways of visualizing the trees
  • +
  • Printing out as text
  • +
  • Algorithms for Setting up Decision Trees
  • +
  • The CART algorithm for Classification
  • +
  • The CART algorithm for Regression
  • +
  • Computing the Gini index
  • +
  • Simple Python Code to read in Data and perform Classification
  • +
  • Computing the Gini Factor
  • +
  • Entropy and the ID3 algorithm
  • +
  • Cancer Data again now with Decision Trees and other Methods
  • +
  • Another example, the moons again
  • +
  • Playing around with regions
  • +
  • Regression trees
  • +
  • Final regressor code
  • +
  • Pros and cons of trees, pros
  • +
  • Disadvantages
  • +
  • Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
  • +
  • An Overview of Ensemble Methods
  • +
  • Bagging
  • +
  • More bagging
  • +
  • Simple Voting Example, head or tail
  • +
  • Using the Voting Classifier
  • +
  • Please, not the moons again! Voting and Bagging
  • +
  • Bagging Examples
  • +
  • Making your own Bootstrap: Changing the Level of the Decision Tree
  • @@ -363,7 +365,7 @@ MathJax.Hub.Config({
  • 9
  • 10
  • ...
  • -
  • 62
  • +
  • 63
  • »
  • diff --git a/doc/pub/week44/html/week44-reveal.html b/doc/pub/week44/html/week44-reveal.html index 117172fde..4a3ed90e0 100644 --- a/doc/pub/week44/html/week44-reveal.html +++ b/doc/pub/week44/html/week44-reveal.html @@ -223,6 +223,19 @@ MathJax.Hub.Config({
    +
    +

    Digression First

    + +

    For those of you interested in the fast growing areas of applications of Machine Learning, this article about Applications and techniques for fast machine learning in science may be interesting.

    + +

    It has several interesting perspectives and highly interesting +applications that link scientific discoveries with efficient software +and hardware. The emphasis is onintegrating power Machine Learning +methods into the real-time experimental data processing loop to +accelerate scientific discovery. +

    +
    +

    Thursday, Principal Component Analysis

    diff --git a/doc/pub/week44/html/week44-solarized.html b/doc/pub/week44/html/week44-solarized.html index 74aec4fc7..5576a37cf 100644 --- a/doc/pub/week44/html/week44-solarized.html +++ b/doc/pub/week44/html/week44-solarized.html @@ -64,6 +64,7 @@ div.toc p,a {









    +

    Digression First

    + +

    For those of you interested in the fast growing areas of applications of Machine Learning, this article about Applications and techniques for fast machine learning in science may be interesting.

    + +

    It has several interesting perspectives and highly interesting +applications that link scientific discoveries with efficient software +and hardware. The emphasis is onintegrating power Machine Learning +methods into the real-time experimental data processing loop to +accelerate scientific discovery. +

    +









    Thursday, Principal Component Analysis

    diff --git a/doc/pub/week44/html/week44.html b/doc/pub/week44/html/week44.html index 357090069..af429774f 100644 --- a/doc/pub/week44/html/week44.html +++ b/doc/pub/week44/html/week44.html @@ -141,6 +141,7 @@ div.toc p,a {









    +

    Digression First

    + +

    For those of you interested in the fast growing areas of applications of Machine Learning, this article about Applications and techniques for fast machine learning in science may be interesting.

    + +

    It has several interesting perspectives and highly interesting +applications that link scientific discoveries with efficient software +and hardware. The emphasis is onintegrating power Machine Learning +methods into the real-time experimental data processing loop to +accelerate scientific discovery. +

    +









    Thursday, Principal Component Analysis

    diff --git a/doc/pub/week44/ipynb/ipynb-week44-src.tar.gz b/doc/pub/week44/ipynb/ipynb-week44-src.tar.gz index 70974fd50898bd3bbbdb8de7acd77c4a2046a917..f0326d4c216a96bf58ab1a98be2526aa650b0a24 100644 GIT binary patch delta 29 kcmeDFE!h2AkWIdugJExXBU>vQV=Eg|D;x7xHkQ^}0GhiA9smFU delta 29 kcmeDFE!h2AkWIdugCVWGk*$@Dv6YRfm5q5T8%t{~0F+q>!vFvP diff --git a/doc/pub/week44/ipynb/week44.ipynb b/doc/pub/week44/ipynb/week44.ipynb index 6520dd5cd..148dc25aa 100644 --- a/doc/pub/week44/ipynb/week44.ipynb +++ b/doc/pub/week44/ipynb/week44.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "fd38e0d8", + "id": "cd360e01", "metadata": { "editable": true }, @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "6c3ff3e8", + "id": "79e2594a", "metadata": { "editable": true }, @@ -29,7 +29,7 @@ }, { "cell_type": "markdown", - "id": "6ef2c3a9", + "id": "059c8e58", "metadata": { "editable": true }, @@ -57,7 +57,25 @@ }, { "cell_type": "markdown", - "id": "43064285", + "id": "5b8367b3", + "metadata": { + "editable": true + }, + "source": [ + "## Digression First\n", + "\n", + "For those of you interested in the fast growing areas of applications of Machine Learning, this article about [Applications and techniques for fast machine learning in science](https://arxiv.org/abs/2110.13041) may be interesting.\n", + "\n", + "It has several interesting perspectives and highly interesting\n", + "applications that link scientific discoveries with efficient software\n", + "and hardware. The emphasis is onintegrating power Machine Learning\n", + "methods into the real-time experimental data processing loop to\n", + "accelerate scientific discovery." + ] + }, + { + "cell_type": "markdown", + "id": "39b2aa0f", "metadata": { "editable": true }, @@ -70,7 +88,7 @@ }, { "cell_type": "markdown", - "id": "cf8aafdd", + "id": "33b3b595", "metadata": { "editable": true }, @@ -104,7 +122,7 @@ }, { "cell_type": "markdown", - "id": "6aebf83b", + "id": "4c8e7761", "metadata": { "editable": true }, @@ -124,7 +142,7 @@ }, { "cell_type": "markdown", - "id": "448179d1", + "id": "b7f04b4c", "metadata": { "editable": true }, @@ -140,7 +158,7 @@ }, { "cell_type": "markdown", - "id": "a3c582bb", + "id": "bfabe4ae", "metadata": { "editable": true }, @@ -153,7 +171,7 @@ }, { "cell_type": "markdown", - "id": "cdfc03f9", + "id": "065596cf", "metadata": { "editable": true }, @@ -165,7 +183,7 @@ }, { "cell_type": "markdown", - "id": "f0cf8552", + "id": "3e8c4e9a", "metadata": { "editable": true }, @@ -187,7 +205,7 @@ }, { "cell_type": "markdown", - "id": "7c91a1dd", + "id": "908482ea", "metadata": { "editable": true }, @@ -199,7 +217,7 @@ }, { "cell_type": "markdown", - "id": "1452784b", + "id": "72a1f54a", "metadata": { "editable": true }, @@ -216,7 +234,7 @@ }, { "cell_type": "markdown", - "id": "62ce3fd7", + "id": "b21f4a92", "metadata": { "editable": true }, @@ -227,7 +245,7 @@ }, { "cell_type": "markdown", - "id": "378401eb", + "id": "e8fb7786", "metadata": { "editable": true }, @@ -245,7 +263,7 @@ }, { "cell_type": "markdown", - "id": "54aa41a4", + "id": "aad3ccbb", "metadata": { "editable": true }, @@ -259,7 +277,7 @@ }, { "cell_type": "markdown", - "id": "396ed097", + "id": "31e869dc", "metadata": { "editable": true }, @@ -278,7 +296,7 @@ }, { "cell_type": "markdown", - "id": "32494a0e", + "id": "40d43074", "metadata": { "editable": true }, @@ -295,7 +313,7 @@ }, { "cell_type": "markdown", - "id": "29b1820f", + "id": "ca76119c", "metadata": { "editable": true }, @@ -307,7 +325,7 @@ }, { "cell_type": "markdown", - "id": "7f45e3c7", + "id": "95090b1f", "metadata": { "editable": true }, @@ -328,7 +346,7 @@ }, { "cell_type": "markdown", - "id": "c27610df", + "id": "31831318", "metadata": { "editable": true }, @@ -342,7 +360,7 @@ }, { "cell_type": "markdown", - "id": "8e3fe536", + "id": "8c678767", "metadata": { "editable": true }, @@ -353,7 +371,7 @@ }, { "cell_type": "markdown", - "id": "2a592b6b", + "id": "319eadd9", "metadata": { "editable": true }, @@ -370,7 +388,7 @@ }, { "cell_type": "markdown", - "id": "b74bfd44", + "id": "6b2bc936", "metadata": { "editable": true }, @@ -380,7 +398,7 @@ }, { "cell_type": "markdown", - "id": "e3933d71", + "id": "bb1dccc7", "metadata": { "editable": true }, @@ -398,7 +416,7 @@ }, { "cell_type": "markdown", - "id": "dcb7cc39", + "id": "889e64d9", "metadata": { "editable": true }, @@ -418,7 +436,7 @@ }, { "cell_type": "markdown", - "id": "7236c638", + "id": "766af5f3", "metadata": { "editable": true }, @@ -438,7 +456,7 @@ { "cell_type": "code", "execution_count": 1, - "id": "2816ddfb", + "id": "069d4c7d", "metadata": { "collapsed": false, "editable": true @@ -460,7 +478,7 @@ }, { "cell_type": "markdown", - "id": "2b88b5ba", + "id": "b7d39bb0", "metadata": { "editable": true }, @@ -472,7 +490,7 @@ { "cell_type": "code", "execution_count": 2, - "id": "0402b74c", + "id": "b49760ba", "metadata": { "collapsed": false, "editable": true @@ -532,7 +550,7 @@ }, { "cell_type": "markdown", - "id": "f29f1b28", + "id": "2226511c", "metadata": { "editable": true }, @@ -546,7 +564,7 @@ { "cell_type": "code", "execution_count": 3, - "id": "fefc95ef", + "id": "f55c9436", "metadata": { "collapsed": false, "editable": true @@ -591,7 +609,7 @@ }, { "cell_type": "markdown", - "id": "01a0c478", + "id": "7efbb6fc", "metadata": { "editable": true }, @@ -602,7 +620,7 @@ { "cell_type": "code", "execution_count": 4, - "id": "5697213c", + "id": "2b41d794", "metadata": { "collapsed": false, "editable": true @@ -626,7 +644,7 @@ }, { "cell_type": "markdown", - "id": "bcbb46a7", + "id": "54992d5b", "metadata": { "editable": true }, @@ -645,7 +663,7 @@ }, { "cell_type": "markdown", - "id": "95ca6ffd", + "id": "894137b5", "metadata": { "editable": true }, @@ -656,7 +674,7 @@ { "cell_type": "code", "execution_count": 5, - "id": "83a86a7c", + "id": "397b0e4d", "metadata": { "collapsed": false, "editable": true @@ -712,7 +730,7 @@ }, { "cell_type": "markdown", - "id": "e76b96db", + "id": "ff4b31c8", "metadata": { "editable": true }, @@ -725,7 +743,7 @@ { "cell_type": "code", "execution_count": 6, - "id": "21ed13c9", + "id": "4490b131", "metadata": { "collapsed": false, "editable": true @@ -750,7 +768,7 @@ { "cell_type": "code", "execution_count": 7, - "id": "505396c4", + "id": "47834875", "metadata": { "collapsed": false, "editable": true @@ -829,7 +847,7 @@ }, { "cell_type": "markdown", - "id": "fc2300b9", + "id": "4f0b2422", "metadata": { "editable": true }, @@ -860,7 +878,7 @@ }, { "cell_type": "markdown", - "id": "c0050e7e", + "id": "818ad6d1", "metadata": { "editable": true }, @@ -880,7 +898,7 @@ }, { "cell_type": "markdown", - "id": "604719f7", + "id": "dcdda417", "metadata": { "editable": true }, @@ -892,7 +910,7 @@ }, { "cell_type": "markdown", - "id": "024eae99", + "id": "28eb8b0d", "metadata": { "editable": true }, @@ -904,7 +922,7 @@ }, { "cell_type": "markdown", - "id": "c76098a4", + "id": "e01a916b", "metadata": { "editable": true }, @@ -922,7 +940,7 @@ }, { "cell_type": "markdown", - "id": "3192d777", + "id": "93c7f697", "metadata": { "editable": true }, @@ -945,7 +963,7 @@ }, { "cell_type": "markdown", - "id": "e7529939", + "id": "3b5b070b", "metadata": { "editable": true }, @@ -968,7 +986,7 @@ }, { "cell_type": "markdown", - "id": "5b546180", + "id": "7cc2bd73", "metadata": { "editable": true }, @@ -979,7 +997,7 @@ { "cell_type": "code", "execution_count": 8, - "id": "7e91ef91", + "id": "04fd4471", "metadata": { "collapsed": false, "editable": true @@ -1078,7 +1096,7 @@ }, { "cell_type": "markdown", - "id": "fa222ce6", + "id": "386c8882", "metadata": { "editable": true }, @@ -1100,7 +1118,7 @@ }, { "cell_type": "markdown", - "id": "4634c4f2", + "id": "b980b6a4", "metadata": { "editable": true }, @@ -1112,7 +1130,7 @@ }, { "cell_type": "markdown", - "id": "c294baf2", + "id": "c863fe52", "metadata": { "editable": true }, @@ -1123,7 +1141,7 @@ }, { "cell_type": "markdown", - "id": "89802073", + "id": "6ba3c8f5", "metadata": { "editable": true }, @@ -1145,7 +1163,7 @@ }, { "cell_type": "markdown", - "id": "d7e26454", + "id": "ae904155", "metadata": { "editable": true }, @@ -1158,7 +1176,7 @@ }, { "cell_type": "markdown", - "id": "259d0e6b", + "id": "db635d76", "metadata": { "editable": true }, @@ -1170,7 +1188,7 @@ }, { "cell_type": "markdown", - "id": "e9f55ddc", + "id": "2e74637b", "metadata": { "editable": true }, @@ -1180,7 +1198,7 @@ }, { "cell_type": "markdown", - "id": "68e72d27", + "id": "aaf633fb", "metadata": { "editable": true }, @@ -1192,7 +1210,7 @@ }, { "cell_type": "markdown", - "id": "e5283250", + "id": "f6e68b1c", "metadata": { "editable": true }, @@ -1202,7 +1220,7 @@ }, { "cell_type": "markdown", - "id": "927623d6", + "id": "b11ee68e", "metadata": { "editable": true }, @@ -1214,7 +1232,7 @@ }, { "cell_type": "markdown", - "id": "f8898aad", + "id": "a3269bff", "metadata": { "editable": true }, @@ -1247,7 +1265,7 @@ }, { "cell_type": "markdown", - "id": "7d19004a", + "id": "83af9705", "metadata": { "editable": true }, @@ -1271,7 +1289,7 @@ }, { "cell_type": "markdown", - "id": "971c60f2", + "id": "aa4cb960", "metadata": { "editable": true }, @@ -1283,7 +1301,7 @@ }, { "cell_type": "markdown", - "id": "3b4c65cb", + "id": "de4dc587", "metadata": { "editable": true }, @@ -1295,7 +1313,7 @@ }, { "cell_type": "markdown", - "id": "df2710a5", + "id": "6a45fc94", "metadata": { "editable": true }, @@ -1323,7 +1341,7 @@ }, { "cell_type": "markdown", - "id": "453c4a34", + "id": "755c30ad", "metadata": { "editable": true }, @@ -1349,7 +1367,7 @@ }, { "cell_type": "markdown", - "id": "d1c3a976", + "id": "c10f79f8", "metadata": { "editable": true }, @@ -1372,7 +1390,7 @@ }, { "cell_type": "markdown", - "id": "766031a4", + "id": "f9bb2e6e", "metadata": { "editable": true }, @@ -1399,7 +1417,7 @@ }, { "cell_type": "markdown", - "id": "a70e3eee", + "id": "311db5f0", "metadata": { "editable": true }, @@ -1418,7 +1436,7 @@ }, { "cell_type": "markdown", - "id": "15bc72a2", + "id": "a2f91713", "metadata": { "editable": true }, @@ -1430,7 +1448,7 @@ }, { "cell_type": "markdown", - "id": "6abce4c5", + "id": "ef5ed076", "metadata": { "editable": true }, @@ -1443,7 +1461,7 @@ }, { "cell_type": "markdown", - "id": "256b2da9", + "id": "614f9ebe", "metadata": { "editable": true }, @@ -1455,7 +1473,7 @@ }, { "cell_type": "markdown", - "id": "332b3989", + "id": "0b2fe813", "metadata": { "editable": true }, @@ -1465,7 +1483,7 @@ }, { "cell_type": "markdown", - "id": "8e0f6aa1", + "id": "b7b63a15", "metadata": { "editable": true }, @@ -1477,7 +1495,7 @@ }, { "cell_type": "markdown", - "id": "4b60775d", + "id": "d53e92a9", "metadata": { "editable": true }, @@ -1487,7 +1505,7 @@ }, { "cell_type": "markdown", - "id": "8055a366", + "id": "60a43e3e", "metadata": { "editable": true }, @@ -1499,7 +1517,7 @@ }, { "cell_type": "markdown", - "id": "3d344070", + "id": "cd4cabda", "metadata": { "editable": true }, @@ -1510,7 +1528,7 @@ { "cell_type": "code", "execution_count": 9, - "id": "9a2453f7", + "id": "a26f2c25", "metadata": { "collapsed": false, "editable": true @@ -1554,7 +1572,7 @@ }, { "cell_type": "markdown", - "id": "296a2d7e", + "id": "e0f0ef09", "metadata": { "editable": true }, @@ -1565,7 +1583,7 @@ { "cell_type": "code", "execution_count": 10, - "id": "4a4c7a93", + "id": "8c53b7c6", "metadata": { "collapsed": false, "editable": true @@ -1600,7 +1618,7 @@ }, { "cell_type": "markdown", - "id": "9a8ab8e1", + "id": "fa34f6c0", "metadata": { "editable": true }, @@ -1613,7 +1631,7 @@ { "cell_type": "code", "execution_count": 11, - "id": "14a20bc0", + "id": "c6a0e408", "metadata": { "collapsed": false, "editable": true @@ -1631,7 +1649,7 @@ }, { "cell_type": "markdown", - "id": "8c19228d", + "id": "d1bdb68a", "metadata": { "editable": true }, @@ -1645,7 +1663,7 @@ { "cell_type": "code", "execution_count": 12, - "id": "965cc27c", + "id": "ebe595f8", "metadata": { "collapsed": false, "editable": true @@ -1664,7 +1682,7 @@ }, { "cell_type": "markdown", - "id": "46b15f90", + "id": "ae08edff", "metadata": { "editable": true }, @@ -1684,7 +1702,7 @@ }, { "cell_type": "markdown", - "id": "9bc8fd9d", + "id": "087a0529", "metadata": { "editable": true }, @@ -1701,7 +1719,7 @@ }, { "cell_type": "markdown", - "id": "ed4103b7", + "id": "d6016c5e", "metadata": { "editable": true }, @@ -1713,7 +1731,7 @@ }, { "cell_type": "markdown", - "id": "ec0df225", + "id": "b063feb6", "metadata": { "editable": true }, @@ -1730,7 +1748,7 @@ }, { "cell_type": "markdown", - "id": "da2a041e", + "id": "f07f9c59", "metadata": { "editable": true }, @@ -1743,7 +1761,7 @@ }, { "cell_type": "markdown", - "id": "4930ddb1", + "id": "25bc315d", "metadata": { "editable": true }, @@ -1755,7 +1773,7 @@ }, { "cell_type": "markdown", - "id": "dd73f833", + "id": "abdd426a", "metadata": { "editable": true }, @@ -1765,7 +1783,7 @@ }, { "cell_type": "markdown", - "id": "ef85e4e8", + "id": "75254813", "metadata": { "editable": true }, @@ -1777,7 +1795,7 @@ }, { "cell_type": "markdown", - "id": "1e55b707", + "id": "f96d7eba", "metadata": { "editable": true }, @@ -1787,7 +1805,7 @@ }, { "cell_type": "markdown", - "id": "e6f85924", + "id": "a59f240b", "metadata": { "editable": true }, @@ -1799,7 +1817,7 @@ }, { "cell_type": "markdown", - "id": "b7237203", + "id": "8eff4224", "metadata": { "editable": true }, @@ -1812,7 +1830,7 @@ }, { "cell_type": "markdown", - "id": "79e7d097", + "id": "5e94289d", "metadata": { "editable": true }, @@ -1856,7 +1874,7 @@ }, { "cell_type": "markdown", - "id": "d35f3238", + "id": "4825caec", "metadata": { "editable": true }, @@ -1867,7 +1885,7 @@ { "cell_type": "code", "execution_count": 13, - "id": "9c4b7ecd", + "id": "10173cb3", "metadata": { "collapsed": false, "editable": true @@ -1945,7 +1963,7 @@ }, { "cell_type": "markdown", - "id": "041c5a97", + "id": "5a99ca75", "metadata": { "editable": true }, @@ -1963,7 +1981,7 @@ { "cell_type": "code", "execution_count": 14, - "id": "36082650", + "id": "59c63ba0", "metadata": { "collapsed": false, "editable": true @@ -2034,7 +2052,7 @@ }, { "cell_type": "markdown", - "id": "3e9509a7", + "id": "2addd397", "metadata": { "editable": true }, @@ -2073,7 +2091,7 @@ }, { "cell_type": "markdown", - "id": "5bf851b9", + "id": "ee7d4ca0", "metadata": { "editable": true }, @@ -2084,7 +2102,7 @@ { "cell_type": "code", "execution_count": 15, - "id": "ac5f7056", + "id": "44bffae1", "metadata": { "collapsed": false, "editable": true @@ -2136,7 +2154,7 @@ }, { "cell_type": "markdown", - "id": "2a232d82", + "id": "88286290", "metadata": { "editable": true }, @@ -2147,7 +2165,7 @@ { "cell_type": "code", "execution_count": 16, - "id": "44256756", + "id": "30773cfa", "metadata": { "collapsed": false, "editable": true @@ -2222,7 +2240,7 @@ }, { "cell_type": "markdown", - "id": "221ee0ba", + "id": "d5620344", "metadata": { "editable": true }, @@ -2233,7 +2251,7 @@ { "cell_type": "code", "execution_count": 17, - "id": "92ef9d3a", + "id": "85b1d60f", "metadata": { "collapsed": false, "editable": true @@ -2264,7 +2282,7 @@ }, { "cell_type": "markdown", - "id": "81695124", + "id": "470b3c72", "metadata": { "editable": true }, @@ -2275,7 +2293,7 @@ { "cell_type": "code", "execution_count": 18, - "id": "c6a904c6", + "id": "263d7105", "metadata": { "collapsed": false, "editable": true @@ -2293,7 +2311,7 @@ { "cell_type": "code", "execution_count": 19, - "id": "235d0491", + "id": "ae820c0e", "metadata": { "collapsed": false, "editable": true @@ -2308,7 +2326,7 @@ }, { "cell_type": "markdown", - "id": "8e7a75d7", + "id": "70eaffe8", "metadata": { "editable": true }, @@ -2319,7 +2337,7 @@ { "cell_type": "code", "execution_count": 20, - "id": "a61e635c", + "id": "24ed3078", "metadata": { "collapsed": false, "editable": true @@ -2369,7 +2387,7 @@ { "cell_type": "code", "execution_count": 21, - "id": "186bdc47", + "id": "d9bb3ae2", "metadata": { "collapsed": false, "editable": true @@ -2408,7 +2426,7 @@ }, { "cell_type": "markdown", - "id": "7d006a18", + "id": "e4b2361d", "metadata": { "editable": true }, @@ -2432,7 +2450,7 @@ }, { "cell_type": "markdown", - "id": "d03c23fb", + "id": "84042182", "metadata": { "editable": true }, @@ -2460,7 +2478,7 @@ }, { "cell_type": "markdown", - "id": "904928d5", + "id": "dda7fd42", "metadata": { "editable": true }, @@ -2491,7 +2509,7 @@ }, { "cell_type": "markdown", - "id": "91e7c067", + "id": "ab23b0ce", "metadata": { "editable": true }, @@ -2507,7 +2525,7 @@ }, { "cell_type": "markdown", - "id": "80280510", + "id": "09ef654d", "metadata": { "editable": true }, @@ -2529,7 +2547,7 @@ }, { "cell_type": "markdown", - "id": "905cf839", + "id": "040a57a1", "metadata": { "editable": true }, @@ -2561,7 +2579,7 @@ }, { "cell_type": "markdown", - "id": "86a459e0", + "id": "837a1737", "metadata": { "editable": true }, @@ -2572,7 +2590,7 @@ { "cell_type": "code", "execution_count": 22, - "id": "f894b9dc", + "id": "ab010a75", "metadata": { "collapsed": false, "editable": true @@ -2596,7 +2614,7 @@ }, { "cell_type": "markdown", - "id": "4b167dbf", + "id": "cfe1c4d0", "metadata": { "editable": true }, @@ -2607,7 +2625,7 @@ { "cell_type": "code", "execution_count": 23, - "id": "a0aab2b8", + "id": "671cf3dc", "metadata": { "collapsed": false, "editable": true @@ -2661,7 +2679,7 @@ }, { "cell_type": "markdown", - "id": "180e23e5", + "id": "4df9bb50", "metadata": { "editable": true }, @@ -2672,7 +2690,7 @@ { "cell_type": "code", "execution_count": 24, - "id": "85b6c772", + "id": "c9a29b91", "metadata": { "collapsed": false, "editable": true @@ -2702,7 +2720,7 @@ { "cell_type": "code", "execution_count": 25, - "id": "94114f95", + "id": "6c357d4f", "metadata": { "collapsed": false, "editable": true @@ -2720,7 +2738,7 @@ { "cell_type": "code", "execution_count": 26, - "id": "2cbc2e88", + "id": "5fec2316", "metadata": { "collapsed": false, "editable": true @@ -2740,7 +2758,7 @@ { "cell_type": "code", "execution_count": 27, - "id": "7715994c", + "id": "401e905d", "metadata": { "collapsed": false, "editable": true @@ -2757,7 +2775,7 @@ }, { "cell_type": "markdown", - "id": "a924b528", + "id": "88c539be", "metadata": { "editable": true }, @@ -2768,7 +2786,7 @@ { "cell_type": "code", "execution_count": 28, - "id": "a8d0d86a", + "id": "ca63ff74", "metadata": { "collapsed": false, "editable": true @@ -2788,7 +2806,7 @@ { "cell_type": "code", "execution_count": 29, - "id": "f02e6b57", + "id": "4b4ae266", "metadata": { "collapsed": false, "editable": true @@ -2802,7 +2820,7 @@ { "cell_type": "code", "execution_count": 30, - "id": "d4aaace9", + "id": "0c7094e1", "metadata": { "collapsed": false, "editable": true @@ -2818,7 +2836,7 @@ { "cell_type": "code", "execution_count": 31, - "id": "cd109964", + "id": "eb5c6446", "metadata": { "collapsed": false, "editable": true @@ -2856,7 +2874,7 @@ }, { "cell_type": "markdown", - "id": "f81562dc", + "id": "0353b2ae", "metadata": { "editable": true }, @@ -2870,7 +2888,7 @@ { "cell_type": "code", "execution_count": 32, - "id": "a3de41ca", + "id": "bee8341b", "metadata": { "collapsed": false, "editable": true diff --git a/doc/src/week44/week44.do.txt b/doc/src/week44/week44.do.txt index ea69f6cda..6393c6123 100644 --- a/doc/src/week44/week44.do.txt +++ b/doc/src/week44/week44.do.txt @@ -20,6 +20,18 @@ o Decision Trees: Geron's chapter 6 covers decision trees while ensemble models, o Clustering and PCA, see Geron's chapter 8 and "Lecture notes":"https://compphysics.github.io/MachineLearning/doc/LectureNotes/_build/html/chapter8.html" !eblock +!split +===== Digression First ===== + +For those of you interested in the fast growing areas of applications of Machine Learning, this article about "Applications and techniques for fast machine learning in science":"https://arxiv.org/abs/2110.13041" may be interesting. + +It has several interesting perspectives and highly interesting +applications that link scientific discoveries with efficient software +and hardware. The emphasis is onintegrating power Machine Learning +methods into the real-time experimental data processing loop to +accelerate scientific discovery. + + !split ===== Thursday, Principal Component Analysis =====