Download presentation
Presentation is loading. Please wait.
1
Data Science Algorithms: The Basic Methods
Decision Trees WFH: Data Mining, Chapter 4.3 Rodney Nielsen Many of these slides were adapted from: I. H. Witten, E. Frank and M. A. Hall
2
Algorithms: The Basic Methods
Inferring rudimentary rules Naïve Bayes, probabilistic model Constructing decision trees Constructing rules Association rule learning Linear models Instance-based learning Clustering
3
Decision Trees
4
Constructing Decision Trees
Strategy: top down Recursive divide-and-conquer fashion First: select attribute for root node Create branch for each possible attribute value Then: split instances into subsets One for each branch extending from the node Finally: repeat recursively for each branch, using only instances that reach the branch Stop if all instances have the same class
5
DT: Algorithm Learning: Depth-first greedy search through the state space Top down, recursive, divide and conquer Select attribute for node Create branch for each value Split instances into subsets One for each branch Repeat recursively, using only instances that reach the branch Stop if all instances have same class This example assumes numeric features Consider weather example
6
DT: Algorithm Classification:
Run through tree according to attribute values Note: this example assumes each xi is numeric x1<α1 x x2<α2 x3<α3 x4<α4 This example assumes numeric features Consider weather example
7
DT: ID3 Learning Algorithm
ID3(trainingData, attributes) recursive function If (attributes=) OR (all/most trainingData is in one class) return leaf node predicting the majority class x* f best attribute to split on Nd f Create decision node splitting on x* For each possible value, vk, of x* addChild(ID3(trainingData subset with x*=vk , attributes – x*)) (assumes k-way split on categorical ftr) return Nd Student Q: Since Divide and Conquer Decision Trees are recursive, would they be preferred for massive amounts of data?
8
DT: Attribute Selection
Evaluate each attribute Use heuristic choice (generally based on statistics or information theory) x1 x2 x3 - - + + - + - + + - - + + - - - - + - - + - + + + + - + + - - + + - - - + - -
9
DT: Inductive Bias Inductive bias Small vs. Large Trees Occam’s Razor
Student Q: Is it better to have a more extensive (larger) decision tree, or a less extensive (smaller) decision tree? Why do you think so?
10
Which Attribute to Select?
64% yes 36% no 60% 100% 60% 57% 86% 75% 50% 50% 75% 67%
11
Which Attribute to Select?
64% yes 36% no 60% 100% 60% 57% 86% 75% 50% 50% 75% 67%
12
Criterion for Attribute Selection
Which is the best attribute? Heuristic: choose the attribute that produces the “purest” nodes Want to get the smallest tree Popular impurity criterion: information gain Information gain increases as the purity of a subset/leaf increases Strategy: choose attribute that gives greatest information gain Student Q: Why should we seek purity in our decision nodes?
13
Computing Information Gain
Measure information in bits Given a probability distribution, the information required to predict/specify an event is the distribution’s entropy Entropy gives the information required in bits (can involve fractions of bits!) Formula for computing the entropy: entropy(p1, p2,…, pn) = - p1 log p1 - p2 log p2 - … - pn log pn Specifying the outcome of a fair coin flip: entropy(0.5,0.5) = -0.5 log log 0.5 = 1.0 Specifying the outcome from a roll of a die: entropy(1/6,1/6,1/6,1/6,1/6,1/6) = 6 * (-1/6 log 1/6) = 2.58
14
Entropy H(X) = Entropy(X) [0,N] [N/2,N/2] [N,0]
15
Example: Attribute Outlook
Outlook = Sunny : Outlook = Overcast : Outlook = Rainy : Expected information for attribute: Info([2,3]) = entropy(2/5,3/5) = -2/5 log(2/5) – 3/5 log(3/5) = bits Note: this is normally undefined. Info([4,0]) = entropy(1,0) = -1 log(1) - 0 log(0) = 0.0 bits Info([3,2]) = entropy(3/5,2/5) = - 3/5 log(3/5) – 2/5 log(2/5) = bits Info([3,2],[4,0],[3,2]) = (5/14) x (4/14) x 0 + (5/14) x = bits
16
Computing Information Gain
Information gain: unknown info before splitting - unknown info after splitting Information gain for attributes from weather data: gain(Outlook ) = info([9,5]) - info([2,3],[4,0],[3,2]) = = bits gain(Outlook) = bits gain(Temperature) = bits gain(Humidity) = bits gain(Windy) = bits
17
DT: Information Gain Decrease in entropy as a result of partitioning the data Ex: X=[6+,7-], H(X)= -6/13 log26/13 -7/13 log27/13 = 0.996 InfoGain = 0.996 3/13(-1 log21 – 0 log20) -10/13(-.4 log log2.6) = 0.249 InfoGain = 0.996 6/13(-5/6 log25/6 -1/6 log21/6) -7/13(-2/7 log22/7 -5/7 log25/7) = 0.231 0.996 – 2/13(-1 log21 -0 log20) 4/13(-3/4 log23/4 -1/4 log21/4) -7/13(-2/7 log22/7 -5/7 log25/7) = 0.281 x1 - + x2 - + x3 - +
18
DT: ID3 Learning Algorithm
ID3(trainingData, attributes) If (attributes=) OR (all trainingData is in one class) return leaf node predicting the majority class x* f best attribute to split on Nd f Create decision node splitting on x* attributesLeft f attributes – x* (assumes k-way split on categorical ftr) For each possible value, vk, of x* addChild(ID3(trainingData subset with x*=vk , attributesLeft)) return Nd
19
DT: Inductive Bias Inductive bias Small vs. Large Trees Occam’s Razor
20
Continuing to Split gain(Temperature ) = 0.571 bits
gain(Windy ) = bits gain(Humidity ) = bits
21
Final Decision Tree Note: not all leaves need to be pure; sometimes identical instances have different classes ID3 Splitting stops when data can’t be split any further
22
Wishlist for a Purity Measure
Properties we require from a purity measure: When node is pure, measure should be zero When impurity is maximal (i.e. all classes equally likely), measure should be maximal Measure should obey multistage property (i.e. decisions can be made in several stages) Entropy is the only function that satisfies all three properties!
23
Highly-Branching Attributes
Problematic: attributes with a large number of values (extreme case: ID code) Subsets are more likely to be pure if there is a large number of values Information gain is biased towards choosing attributes with a large number of values This may result in overfitting (selection of an attribute that performs well on training data, but is non-optimal for prediction) Another problem: fragmentation
24
Weather Data with ID Code
N M L K J I H G F E D C B A ID code No True High Mild Rainy Yes False Normal Hot Overcast Sunny Cool Play Windy Humidity Temp. Outlook
25
Tree Stump for ID Code Attribute
Information gain is maximal for ID code (namely bits)
26
Gain Ratio Gain ratio: a modification of the information gain that reduces its bias Gain ratio takes number and size of branches into account when choosing an attribute It corrects the information gain by taking the intrinsic information of a split into account Intrinsic information: entropy of distribution of instances into branches (i.e. how much info do we need to tell which branch an instance belongs to)
27
Computing the Gain Ratio
Example: intrinsic information for ID code Value of attribute decreases as intrinsic information gets larger Called Split Information Gain Ratio = Information Gain / Split Information Info([1,1…,1]) = -1/14 x log1/14 x 14
28
Gain Ratios for Weather Data
0.019 Gain ratio: 0.029/1.557 0.157 Gain ratio: 0.247/1.577 1.557 Split info: info([4,6,4]) 1.577 Split info: info([5,4,5]) 0.029 Gain: 0.247 Gain: 0.911 Info: 0.693 Temperature Outlook 0.049 Gain ratio: 0.048/0.985 0.152 Gain ratio: 0.152/1 0.985 Split info: info([8,6]) 1.000 Split info: info([7,7]) 0.048 Gain: Gain: 0.892 Info: 0.788 Windy Humidity
29
More on Gain Ratio “Outlook” still comes out top
Problem with gain ratio: it may overcompensate May choose an attribute just because its intrinsic information is very low Standard fix: only consider attributes with greater than average information gain
30
DT: Hypothesis Space Unrestricted hypothesis space + -
31
Discussion Top-down induction of decision trees: ID3, algorithm developed by Ross Quinlan Gain ratio just one modification of this basic algorithm C4.5: deals with numeric attributes, missing values, noisy data Similar approach: CART There are many other attribute selection criteria! (But little difference in accuracy of result)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.