decision trees lecture 11
play

Decision Trees Lecture 11 David Sontag New York - PowerPoint PPT Presentation

Decision Trees Lecture 11 David Sontag New York University Slides adapted from Luke Zettlemoyer, Carlos Guestrin, and Andrew Moore A learning problem: predict fuel efficiency


  1. Decision ¡Trees ¡ Lecture ¡11 ¡ David ¡Sontag ¡ New ¡York ¡University ¡ Slides adapted from Luke Zettlemoyer, Carlos Guestrin, and Andrew Moore

  2. A ¡learning ¡problem: ¡predict ¡fuel ¡efficiency ¡ • 40 ¡data ¡points ¡ • Goal: ¡predict ¡ MPG ¡ • Need ¡to ¡find: ¡ f ¡ ¡ : ¡X ¡  ¡Y ¡ • Discrete ¡data ¡ (for ¡now) ¡ X Y From the UCI repository (thanks to Ross Quinlan)

  3. Hypotheses: decision trees f : X  Y • Each internal node tests an attribute x i Cylinders ¡ • Each branch assigns an attribute 3 ¡ 4 ¡ 5 ¡ 6 ¡ 8 ¡ value x i =v good bad bad Maker ¡ Horsepower ¡ • Each leaf assigns a class y low ¡ med ¡ america ¡ asia ¡ europe ¡ high ¡ • To classify input x : bad good bad good good bad traverse the tree from root to leaf, output the labeled y Human ¡interpretable! ¡

  4. Hypothesis space • How many possible hypotheses? • What functions can be represented? Cylinders ¡ 6 ¡ 3 ¡ 4 ¡ 5 ¡ 8 ¡ bad good bad Maker ¡ Horsepower ¡ america ¡ low ¡ med ¡ high ¡ asia ¡ europe ¡ bad good good good bad bad

  5. What ¡funcPons ¡can ¡be ¡represented? ¡ → A • Decision ¡trees ¡can ¡represent ¡ A B A xor B F T F F F any ¡funcPon ¡of ¡the ¡input ¡ B B F T T F T F T T F T aRributes! ¡ T T F F T T F (Figure ¡from ¡Stuart ¡Russell) ¡ • For ¡Boolean ¡funcPons, ¡path ¡ to ¡leaf ¡gives ¡truth ¡table ¡row ¡ Cylinders ¡ • But, ¡could ¡require ¡ 6 ¡ 3 ¡ 4 ¡ 5 ¡ 8 ¡ exponenPally ¡many ¡nodes… ¡ bad good bad Maker ¡ Horsepower ¡ america ¡ low ¡ med ¡ high ¡ asia ¡ europe ¡ bad good good good bad bad cyl=3 ∨ (cyl=4 ∧ (maker=asia ∨ maker=europe)) ∨ …

  6. Hypothesis space • How many possible hypotheses? • What functions can be represented? • How many will be consistent with a given dataset? Cylinders ¡ • How will we choose the 6 ¡ 3 ¡ 4 ¡ 5 ¡ 8 ¡ bad good bad best one? Maker ¡ Horsepower ¡ • Lets first look at how to split america ¡ low ¡ med ¡ high ¡ asia ¡ europe ¡ nodes, then consider how to bad good good good bad bad find the best tree

  7. What ¡is ¡the ¡ Simplest ¡Tree? ¡ predict ¡ mpg=bad ¡ Is ¡this ¡a ¡good ¡tree? ¡ ¡Means: ¡ ¡ [22+, ¡18-­‑] ¡ ¡ ¡ ¡correct ¡on ¡22 ¡examples ¡ ¡ ¡ ¡incorrect ¡on ¡18 ¡examples ¡

  8. A ¡Decision ¡Stump ¡

  9. Recursive ¡Step ¡ Records in which cylinders = 4 Records in which cylinders = 5 Take the And partition it Original according Records Dataset.. to the value of in which the attribute we cylinders split on = 6 Records in which cylinders = 8

  10. Recursive ¡Step ¡ Build tree from Build tree from Build tree from Build tree from These records.. These records.. These records.. These records.. Records in Records in which cylinders which cylinders = 8 = 6 Records in Records in which cylinders which cylinders = 5 = 4

  11. Second ¡level ¡of ¡tree ¡ Recursively build a tree from the seven (Similar recursion in records in which there are four cylinders the other cases) and the maker was based in Asia

  12. A full tree

  13. Are ¡all ¡decision ¡trees ¡equal? ¡ • Many ¡trees ¡can ¡represent ¡the ¡same ¡concept ¡ • But, ¡not ¡all ¡trees ¡will ¡have ¡the ¡same ¡size! ¡ – e.g., ¡ φ ¡= ¡(A ¡ ∧ ¡B) ¡ ∨ ¡( ¬ A ¡ ∧ C) ¡-­‑-­‑ ¡((A ¡and ¡B) ¡or ¡(not ¡A ¡and ¡C)) ¡ B A t f t f C C B C t t f f t f t f _ _ _ A A + + + t f t f _ _ + + • Which tree do we prefer?

  14. Learning ¡decision ¡trees ¡is ¡hard!!! ¡ • Learning ¡the ¡simplest ¡(smallest) ¡decision ¡tree ¡is ¡ an ¡NP-­‑complete ¡problem ¡[Hyafil ¡& ¡Rivest ¡’76] ¡ ¡ • Resort ¡to ¡a ¡greedy ¡heurisPc: ¡ – Start ¡from ¡empty ¡decision ¡tree ¡ – Split ¡on ¡ next ¡best ¡a2ribute ¡(feature) ¡ – Recurse ¡

  15. Spliing: ¡choosing ¡a ¡good ¡aRribute ¡ Would we prefer to split on X 1 or X 2 ? X 1 X 2 Y T T T T F T X 1 X 2 T T T t f t f T F T Y=t : 4 Y=t : 1 Y=t : 3 Y=t : 2 F T T Y=f : 0 Y=f : 3 Y=f : 1 Y=f : 2 F F F F T F Idea: use counts at leaves to define F F F probability distributions, so we can measure uncertainty!

  16. Measuring ¡uncertainty ¡ • Good ¡split ¡if ¡we ¡are ¡more ¡certain ¡about ¡ classificaPon ¡ajer ¡split ¡ – DeterminisPc ¡good ¡(all ¡true ¡or ¡all ¡false) ¡ – Uniform ¡distribuPon ¡bad ¡ – What ¡about ¡distribuPons ¡in ¡between? ¡ P(Y=A) = 1/2 P(Y=B) = 1/4 P(Y=C) = 1/8 P(Y=D) = 1/8 P(Y=A) = 1/4 P(Y=B) = 1/4 P(Y=C) = 1/4 P(Y=D) = 1/4

  17. Entropy ¡ Entropy ¡ H(Y) ¡of ¡a ¡random ¡variable ¡ Y Entropy ¡of ¡a ¡coin ¡flip ¡ More uncertainty, more entropy! Entropy ¡ Information Theory interpretation: H(Y) is the expected number of bits needed to encode a randomly drawn value of Y (under most efficient code) Probability ¡of ¡heads ¡

  18. High, ¡Low ¡Entropy ¡ • “High ¡Entropy” ¡ ¡ – Y ¡is ¡from ¡a ¡uniform ¡like ¡distribuPon ¡ – Flat ¡histogram ¡ – Values ¡sampled ¡from ¡it ¡are ¡less ¡predictable ¡ • “Low ¡Entropy” ¡ ¡ – Y ¡is ¡from ¡a ¡varied ¡(peaks ¡and ¡valleys) ¡ distribuPon ¡ – Histogram ¡has ¡many ¡lows ¡and ¡highs ¡ – Values ¡sampled ¡from ¡it ¡are ¡more ¡predictable ¡ (Slide from Vibhav Gogate)

  19. Entropy ¡of ¡a ¡coin ¡flip ¡ Entropy ¡Example ¡ Entropy ¡ Probability ¡of ¡heads ¡ P(Y=t) = 5/6 X 1 X 2 Y P(Y=f) = 1/6 T T T T F T H(Y) = - 5/6 log 2 5/6 - 1/6 log 2 1/6 T T T = 0.65 T F T F T T F F F

  20. CondiPonal ¡Entropy ¡ CondiPonal ¡Entropy ¡ H( Y |X) ¡of ¡a ¡random ¡variable ¡ Y ¡condiPoned ¡on ¡a ¡ random ¡variable ¡ X X 1 X 2 Y Example: X 1 T T T t f T F T P(X 1 =t) = 4/6 Y=t : 4 Y=t : 1 T T T P(X 1 =f) = 2/6 Y=f : 0 Y=f : 1 T F T F T T H(Y|X 1 ) = - 4/6 (1 log 2 1 + 0 log 2 0) F F F - 2/6 (1/2 log 2 1/2 + 1/2 log 2 1/2) = 2/6

  21. InformaPon ¡gain ¡ • Decrease ¡in ¡entropy ¡(uncertainty) ¡ajer ¡spliing ¡ X 1 X 2 Y In our running example: T T T T F T IG(X 1 ) = H(Y) – H(Y|X 1 ) T T T = 0.65 – 0.33 T F T IG(X 1 ) > 0  we prefer the split! F T T F F F

  22. Learning ¡decision ¡trees ¡ • Start ¡from ¡empty ¡decision ¡tree ¡ • Split ¡on ¡ next ¡best ¡a2ribute ¡(feature) ¡ – Use, ¡for ¡example, ¡informaPon ¡gain ¡to ¡select ¡ aRribute: ¡ • Recurse ¡

  23. Suppose we want to predict MPG Look ¡at ¡all ¡the ¡ informaPon ¡ gains… ¡

  24. A ¡Decision ¡Stump ¡ First split looks good! But, when do we stop?

  25. Base Case One Don’t split a node if all matching records have the same output value

  26. Base Case Two Don’t split a node if data points are identical on remaining attributes

  27. Base Case Two: No attributes can distinguish

  28. Base ¡Cases: ¡An ¡idea ¡ • Base ¡Case ¡One: ¡If ¡all ¡records ¡in ¡current ¡data ¡ subset ¡have ¡the ¡same ¡output ¡then ¡don’t ¡recurse ¡ • Base ¡Case ¡Two: ¡If ¡all ¡records ¡have ¡exactly ¡the ¡ same ¡set ¡of ¡input ¡aRributes ¡then ¡don’t ¡recurse ¡ Proposed Base Case 3: If all attributes have zero information gain then don’t recurse • Is this a good idea?

  29. The ¡problem ¡with ¡Base ¡Case ¡3 ¡ y = a XOR b The information gains: The resulting decision tree:

  30. If ¡we ¡omit ¡Base ¡Case ¡3: ¡ The resulting decision tree: y = a XOR b Is it OK to omit Base Case 3?

  31. Summary: ¡Building ¡Decision ¡Trees ¡ BuildTree( DataSet,Output ) ¡ • If ¡all ¡output ¡values ¡are ¡the ¡same ¡in ¡ DataSet , ¡return ¡a ¡leaf ¡node ¡ that ¡says ¡“predict ¡this ¡unique ¡output” ¡ • If ¡all ¡input ¡values ¡are ¡the ¡same, ¡return ¡a ¡leaf ¡node ¡that ¡says ¡ “predict ¡the ¡majority ¡output” ¡ • Else ¡find ¡aRribute ¡ X ¡with ¡highest ¡Info ¡Gain ¡ • Suppose ¡ X ¡has ¡ n X ¡disPnct ¡values ¡(i.e. ¡X ¡has ¡arity ¡ n X ). ¡ ¡ – Create ¡a ¡non-­‑leaf ¡node ¡with ¡ n X ¡children. ¡ ¡ – The ¡ i’ th ¡child ¡should ¡be ¡built ¡by ¡calling ¡ BuildTree( DS i , Output ) ¡ Where ¡ DS i ¡ ¡contains ¡the ¡records ¡in ¡DataSet ¡where ¡X ¡= ¡ i th ¡value ¡of ¡X. ¡

  32. MPG Test set error The test set error is much worse than the training set error… …why?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend