Applied Predictive Analytics For Business: Decision Trees
Applied Predictive Analytics For Business: Decision Trees
for Business
Decision Trees
1
Todays Agenda
2
Decision Tree Representation
3
Classification and Regression Trees
4
Top-Down Induction of Decision Trees
5
Regression Trees
customer assets income amount
1 H 75 150
2 L 50 30
3 M 25 25
4 M 50 100
5 M 100 110
6 H 25 200
7 L 25 15
8 M 75 90
Two predictors:
assets = {Low, Medium, High}
Income in 1000s of dollars
Response (quantitative):
Borrowing amount in 1000s of dollars
Goal: Can you create a decision rule (a tree!) to predict the borrowing amount?
6
Building Regression Trees
Regression tree building process:
Suppose we are starting at the root node.
The algorithm considers all the partitions of the predictors
into the left and right nodes and then computes RSS
(Residual Sums of Squares) for each partition.
RSS (Y Yleft )2 (Y Y right
) 2
7
Recursive Partitioning in Action
8
Partition 3
Partition Left Node Right Node RSS
1 Asset = M or H Asset = L ?
2 Asset = L or H Asset = M ?
3 Asset = L or M Asset = H ?
4 Income < 37.5 Income > 37.5 ?
5 Income < 62.5 Income > 62.5 ?
6 Income < 87.5 Income > 87.5 ?
9
Partition 4
Partition Left Node Right Node RSS
1 Asset = M or H Asset = L ?
2 Asset = L or H Asset = M ?
3 Asset = L or M Asset = H ?
4 Income < 37.5 Income > 37.5 ?
5 Income < 62.5 Income > 62.5 ?
6 Income < 87.5 Income > 87.5 ?
10
Executing Tree Commands in R
11
Decision Tree with the Hitters Data Set
12
Cost Complexity Pruning
13
Pruning Through Cost Complexity Analysis
14
Pruned Tree
15
Regression Tree Lab
16
Classification Trees
With 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
17
Growing a Classification Tree
Similar to regression, just cant use RSS.
log 2 log 2
19
Information Gain
20
Decision Tree for Play Tennis
21
Training Examples
Day Outlook Temperature Humidity Wind Play Tennis
D1 Sunny Hot High Weak No
D2 Sunny Hot High Stong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Stong No
D7 Overcast Cool Normal Stong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Stong Yes
D12 Overcast Mild High Stong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Stong No
22
Which attribute is the best classifier?
23
Which attribute should be tested?
,E = 0.940
,E = 0.971 ,E = 0.971
24
Test Temperature
Day Outlook Temperature Humidity Wind Play Tennis
D1 Sunny Hot High Weak No
D2 Sunny Hot High Stong No
D3 Overcast Hot High Weak Yes
D4 Rain Mild High Weak Yes
D5 Rain Cool Normal Weak Yes
D6 Rain Cool Normal Stong No
D7 Overcast Cool Normal Stong Yes
D8 Sunny Mild High Weak No
D9 Sunny Cool Normal Weak Yes
D10 Rain Mild Normal Weak Yes
D11 Sunny Mild Normal Stong Yes
D12 Overcast Mild High Stong Yes
D13 Overcast Hot Normal Weak Yes
D14 Rain Mild High Stong No
28
Advantages of Trees
Most common transformation of the predictors will not change the
tree results. (Transformation of the response could make a
difference.)
Interaction terms (often used in multiple regression) are not used.
They are automatically handled within the context of a tree.
They are easy to visualize. (Unless you have too many
branches.)
There is no need to have dummy variables for categorical data.
They are easy to explain and use.
Missing values can be handled easily.
Many people use trees as an exploratory tool.
29
Disadvantages of Trees
Trees are not generally robust. They can be severely
unstable if small changes in data are made.
Regression trees only give the mean (or mode) of Y
values in the leaves as predictions. Why just a mean?
Often they dont predict well!
There are fixes to the disadvantages but they come at a price: they take away
from the advantages!
80