Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data Mining Practical Machine Learning Tools and Techniques Chapter 4: Algorithms: The Basic Methods Section 4.3: Decision Trees Rodney Nielsen Many of.

Similar presentations


Presentation on theme: "Data Mining Practical Machine Learning Tools and Techniques Chapter 4: Algorithms: The Basic Methods Section 4.3: Decision Trees Rodney Nielsen Many of."— Presentation transcript:

1 Data Mining Practical Machine Learning Tools and Techniques Chapter 4: Algorithms: The Basic Methods Section 4.3: Decision Trees Rodney Nielsen Many of these slides were adapted from: I. H. Witten, E. Frank and M. A. Hall

2 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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 Rodney Nielsen, Human Intelligence & Language Technologies Lab Decision Trees

4 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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 Classification: Run through tree according to attribute values x

6 Rodney Nielsen, Human Intelligence & Language Technologies Lab DT: ID3 Learning Algorithm ID3(trainingData, attributes) If (attributes=  ) OR (all trainingData is in one class) return leaf node predicting the majority class x*  best attribute to split on Nd  Create decision node splitting on x* attributesLeft  attributes – x* For each possible value, v k, of x* addChild(ID3(trainingData subset with x* = v k, attributesLeft)) return Nd

7 Rodney Nielsen, Human Intelligence & Language Technologies Lab DT: Attribute Selection Evaluate each attribute Use heuristic choice (generally based on statistics or information theory) x1x1 x2x2 x3x3 - + - -- - - + + ++ + - + - - - - - + + ++ + - + - - - -- + + ++ + - - -

8 Rodney Nielsen, Human Intelligence & Language Technologies Lab Which Attribute to Select?

9 Rodney Nielsen, Human Intelligence & Language Technologies Lab Which Attribute to Select?

10 Rodney Nielsen, Human Intelligence & Language Technologies Lab Criterion for Attribute Selection ● Which is the best attribute?  Want to get the smallest tree  Heuristic: choose the attribute that produces the “purest” nodes ● Popular impurity criterion: information gain  Information gain increases as the purity of a subset/leaf increases ● Strategy: choose attribute that gives greatest information gain

11 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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(p 1, p 2,…, p n ) = - p 1 log p 1 - p 2 log p 2 - … - p n log p n ● Specifying the outcome of a fair coin flip: entropy(0.5,0.5) = -0.5 log 0.5 -0.5 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

12 Rodney Nielsen, Human Intelligence & Language Technologies Lab Entropy H ( X ) = Entropy ( X ) [0,N][N,0][N/2,N/2]

13 Rodney Nielsen, Human Intelligence & Language Technologies Lab Example: Attribute Outlook ● Outlook = Sunny : ● Outlook = Overcast : ● Outlook = Rainy : ● Expected information for attribute: Note: this is normally undefined. Info([2,3]) = entropy(2/5,3/5) = -2/5 log(2/5) – 3/5 log(3/5) = 0.971 bits 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) = 0.971 bits Info([3,2],[4,0],[3,2]) = (5/14) x 0.971 + (4/14) x 0 + (5/14) x 0.971 = 0.693 bits

14 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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]) = 0.940 - 0.693 = 0.247 bits gain(Outlook) = 0.247 bits gain(Temperature) = 0.029 bits gain(Humidity) = 0.152 bits gain(Windy) = 0.048 bits

15 Rodney Nielsen, Human Intelligence & Language Technologies Lab DT: Information Gain Decrease in entropy as a result of partitioning the data x1x1 - + - -- - - + + ++ + - x2x2 - + - - - - - + + ++ + - x3x3 - + - - - -- + + ++ + - Ex: X=[6+,7-], H(X)= -6/13 log 2 6/13 -7/13 log 2 7/13 = 0.996 InfoGain = 0.996 - 3 / 13 (-1 log 2 1 – 0 log 2 0) - 10 / 13 (-.4 log 2.4 -.6 log 2.6) = 0.249 InfoGain = 0.996 - 6 / 13 (- 5 / 6 log 2 5 / 6 - 1 / 6 log 2 1 / 6 ) - 7 / 13 (- 2 / 7 log 2 2 / 7 - 5 / 7 log 2 5 / 7 ) = 0.231 0.996 – 2 / 13 (-1 log 2 1 -0 log 2 0) - 4 / 13 (- 3 / 4 log 2 3 / 4 - 1 / 4 log 2 1 / 4 ) - 7 / 13 (- 2 / 7 log 2 2 / 7 - 5 / 7 log 2 5 / 7 ) = 0.281

16 Rodney Nielsen, Human Intelligence & Language Technologies Lab DT: ID3 Learning Algorithm ID3(trainingData, attributes) If (attributes=  ) OR (all trainingData is in one class) return leaf node predicting the majority class x*  best attribute to split on Nd  Create decision node splitting on x* attributesLeft  attributes – x* For each possible value, v k, of x* addChild(ID3(trainingData subset with x* = v k, attributesLeft)) return Nd

17 Rodney Nielsen, Human Intelligence & Language Technologies Lab DT: Inductive Bias Inductive bias Smallvs. Large Trees Occam’s Razor

18 Rodney Nielsen, Human Intelligence & Language Technologies Lab Continuing to Split gain(Temperature )= 0.571 bits gain(Windy )= 0.020 bits gain(Humidity ) = 0.971 bits

19 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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

20 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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! Measure([2,3,4])

21 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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

22 Rodney Nielsen, Human Intelligence & Language Technologies Lab Weather Data with ID Code N M L K J I H G F E D C B A ID code NoTrueHighMildRainy YesFalseNormalHotOvercast YesTrueHighMildOvercast YesTrueNormalMildSunny YesFalseNormalMildRainy YesFalseNormalCoolSunny NoFalseHighMildSunny YesTrueNormalCoolOvercast NoTrueNormalCoolRainy YesFalseNormalCoolRainy YesFalseHighMildRainy YesFalseHighHotOvercast NoTrueHighHotSunny NoFalseHighHotSunny PlayWindyHumidityTemp.Outlook

23 Rodney Nielsen, Human Intelligence & Language Technologies Lab Tree Stump for ID Code Attribute ● Entropy of split:  Information gain is maximal for ID code (namely 0.940 bits) info(ID code)

24 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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)

25 Rodney Nielsen, Human Intelligence & Language Technologies Lab Computing the Gain Ratio ● Example: intrinsic information for ID code ● Value of attribute decreases as intrinsic information gets larger info([1,1…,1]) = -1/14 x log1/14 x 14

26 Rodney Nielsen, Human Intelligence & Language Technologies Lab Gain Ratios for Weather Data 0.019Gain ratio: 0.029/1.5570.157Gain ratio: 0.247/1.577 1.557Split info: info([4,6,4])1.577Split info: info([5,4,5]) 0.029Gain: 0.940-0.9110.247Gain: 0.940-0.693 0.911Info:0.693Info: TemperatureOutlook 0.049Gain ratio: 0.048/0.9850.152Gain ratio: 0.152/1 0.985Split info: info([8,6])1.000Split info: info([7,7]) 0.048Gain: 0.940-0.8920.152Gain: 0.940-0.788 0.892Info:0.788Info: WindyHumidity

27 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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

28 Rodney Nielsen, Human Intelligence & Language Technologies Lab DT: Hypothesis Space Unrestricted hypothesis space

29 Rodney Nielsen, Human Intelligence & Language Technologies Lab 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)


Download ppt "Data Mining Practical Machine Learning Tools and Techniques Chapter 4: Algorithms: The Basic Methods Section 4.3: Decision Trees Rodney Nielsen Many of."

Similar presentations


Ads by Google