Decision Trees: Discussion Machine Learning 1 Some slides from Tom - - PowerPoint PPT Presentation

decision trees discussion
SMART_READER_LITE
LIVE PREVIEW

Decision Trees: Discussion Machine Learning 1 Some slides from Tom - - PowerPoint PPT Presentation

Decision Trees: Discussion Machine Learning 1 Some slides from Tom Mitchell, Dan Roth and others This lecture: Learning Decision Trees 1. Representation : What are decision trees? 2. Algorithm : Learning decision trees The ID3 algorithm: A


slide-1
SLIDE 1

Machine Learning

Decision Trees: Discussion

1

Some slides from Tom Mitchell, Dan Roth and others

slide-2
SLIDE 2

This lecture: Learning Decision Trees

  • 1. Representation: What are decision trees?
  • 2. Algorithm: Learning decision trees

– The ID3 algorithm: A greedy heuristic

  • 3. Some extensions

2

slide-3
SLIDE 3

This lecture: Learning Decision Trees

  • 1. Representation: What are decision trees?
  • 2. Algorithm: Learning decision trees

– The ID3 algorithm: A greedy heuristic

  • 3. Some extensions

3

slide-4
SLIDE 4

Tips and Tricks

  • 1. Decision tree variants
  • 2. Handling examples with missing feature values
  • 3. Non-Boolean features
  • 4. Avoiding overfitting

4

slide-5
SLIDE 5
  • 1. Variants of information gain

Information gain is defined using entropy to measure the disorder/impurity of the labels. There are other ways to measure disorder. Eg: MajorityError, Gini Index Example: MajorityError computes:

“Suppose the tree was not grown below this node and the most frequent label were chosen, what would be the error?” Suppose at some node, there are 15 + and 5 - examples. What is the MajorityError? Answer: ¼

Works like entropy

5

slide-6
SLIDE 6
  • 1. Variants of information gain

Information gain is defined using entropy to measure the disorder/impurity of the labels. There are other ways to measure disorder. Eg: MajorityError, Gini Index Example: MajorityError computes:

“Suppose the tree was not grown below this node and the most frequent label were chosen, what would be the error?” Suppose at some node, there are 15 + and 5 - examples. What is the MajorityError? Answer: ¼

Works like entropy

6

slide-7
SLIDE 7
  • 1. Variants of information gain

7

Entropy: − 𝑞 log! 𝑞 + 1 − 𝑞 log! 1 − 𝑞 Let 𝑞 denote the fraction of positive examples. Then 1 − 𝑞 is the fraction of negative examples. Gini Index: 1 − 𝑞! + 1 − 𝑞 ! MajorityError: min(𝑞, 1 − 𝑞) p (fraction of positive examples)

slide-8
SLIDE 8
  • 1. Variants of information gain

8

Entropy: − 𝑞 log! 𝑞 + 1 − 𝑞 log! 1 − 𝑞 Let 𝑞 denote the fraction of positive examples. Then 1 − 𝑞 is the fraction of negative examples. Gini Index: 1 − 𝑞! + 1 − 𝑞 ! MajorityError: min(𝑞, 1 − 𝑞) Each measure peaks when uncertainty is highest (i.e. p = 0.5) p (fraction of positive examples)

slide-9
SLIDE 9
  • 1. Variants of information gain

9

Entropy: − 𝑞 log! 𝑞 + 1 − 𝑞 log! 1 − 𝑞 Let 𝑞 denote the fraction of positive examples. Then 1 − 𝑞 is the fraction of negative examples. Gini Index: 1 − 𝑞! + 1 − 𝑞 ! MajorityError: min(𝑞, 1 − 𝑞) p (fraction of positive examples) Lowest (zero) when uncertainty is lowest (i.e. p=0 or p=1)

slide-10
SLIDE 10
  • 1. Variants of information gain

10

Entropy: − 𝑞 log! 𝑞 + 1 − 𝑞 log! 1 − 𝑞 Let 𝑞 denote the fraction of positive examples. Then 1 − 𝑞 is the fraction of negative examples. Gini Index: 1 − 𝑞! + 1 − 𝑞 ! MajorityError: min(𝑞, 1 − 𝑞) p (fraction of positive examples) Each of these work like entropy. They can replace entropy in the definition of information gain.

slide-11
SLIDE 11
  • 2. Missing feature values

Suppose an example is missing the value of an attribute. What can we do at training time?

11

Day Outlook Temperature Humidity Wind PlayTennis 1 Sunny Hot High Weak No 2 Sunny Hot High Strong No 8 Sunny Mild ??? Weak No 9 Sunny Cool High Weak Yes 11 Sunny Mild Normal Strong Yes

slide-12
SLIDE 12
  • 2. Missing feature values

Suppose an example is missing the value of an attribute. What can we do at training time? Different methods to “Complete the example”:

– Using the most common value of the attribute in the data – Using the most common value of the attribute among all examples with the same output – Using fractional counts of the attribute values

  • Eg: Outlook={5/14 Sunny, 4/14 Overcast, 5/15 Rain}
  • Exercise: Will this change probability computations?

12

slide-13
SLIDE 13
  • 2. Missing feature values

Suppose an example is missing the value of an attribute. What can we do at training time? Different methods to “Complete the example”:

– Using the most common value of the attribute in the data – Using the most common value of the attribute among all examples with the same output – Using fractional counts of the attribute values

  • Eg: Outlook={5/14 Sunny, 4/14 Overcast, 5/15 Rain}
  • Exercise: Will this change probability computations?

At test time?

13

slide-14
SLIDE 14
  • 2. Missing feature values

Suppose an example is missing the value of an attribute. What can we do at training time? Different methods to “Complete the example”:

– Using the most common value of the attribute in the data – Using the most common value of the attribute among all examples with the same output – Using fractional counts of the attribute values

  • Eg: Outlook={5/14 Sunny, 4/14 Overcast, 5/15 Rain}
  • Exercise: Will this change probability computations?

At test time? Use the same method

14

slide-15
SLIDE 15
  • 3. Non-Boolean features
  • If the features can take multiple values

– We have seen one edge per value (i.e a multi-way split)

15

Outlook Overcast Rain Sunny

slide-16
SLIDE 16
  • 3. Non-Boolean features
  • If the features can take multiple values

– We have seen one edge per value (i.e a multi-way split) – Another option: Make the attributes Boolean by testing for each value – Or, perhaps group values into disjoint sets

16

Convert Outlook=Sunny → { Outlook:Sunny=True, Outlook:Overcast=False, Outlook:Rain=False }

slide-17
SLIDE 17
  • 3. Non-Boolean features
  • If the features can take multiple values

– We have seen one edge per value (i.e a multi-way split) – Another option: Make the attributes Boolean by testing for each value – Or, perhaps group values into disjoint sets

  • For numeric features, use thresholds or ranges to get

Boolean/discrete alternatives

17

Convert Outlook=Sunny → { Outlook:Sunny=True, Outlook:Overcast=False, Outlook:Rain=False }

slide-18
SLIDE 18
  • 4. Overfitting

18

slide-19
SLIDE 19

The “First Bit” function

  • A Boolean function with n inputs
  • Simply returns the value of the first input, all others

irrelevant

19

What is the decision tree for this function?

X0 X1 Y F F F F T F T F T T T T

X1 is irrelvant Y = X0

slide-20
SLIDE 20

The “First Bit” function

  • A Boolean function with n inputs
  • Simply returns the value of the first input, all others

irrelevant

20

X0 X1 Y F F F F T F T F T T T T

What is the decision tree for this function? X0

T F

T F

slide-21
SLIDE 21

The “First Bit” function

  • A Boolean function with n inputs
  • Simply returns the value of the first input, all others

irrelevant

21

X0 X1 Y F F F F T F T F T T T T

What is the decision tree for this function? X0

T F

T F

Exercise: Convince yourself that ID3 will generate this tree

slide-22
SLIDE 22

The best case scenario: Perfect data

Suppose we have all 2n examples for training. What will the error be on any future examples? Zero! Because we have seen every possible input! And the decision tree can represent the function and ID3 will build a consistent tree

22

slide-23
SLIDE 23

The best case scenario: Perfect data

Suppose we have all 2n examples for training. What will the error be on any future examples? Zero! Because we have seen every possible input! And the decision tree can represent the function and ID3 will build a consistent tree

23

slide-24
SLIDE 24

Noisy data

What if the data is noisy? And we have all 2n examples.

24

X0 X1 X2 Y F F F F F F T F F T F F F T T F T F F T T F T T T T F T T T T T Suppose, the outputs of both training and test sets are randomly corrupted Train and test sets are no longer identical. Both have noise, possibly different

slide-25
SLIDE 25

Noisy data

What if the data is noisy? And we have all 2n examples.

25

X0 X1 X2 Y F F F F F F T F F T F F F T T F T F F T T F T T T T F T T T T T F T Suppose, the outputs of both training and test sets are randomly corrupted Train and test sets are no longer identical. Both have noise, possibly different

slide-26
SLIDE 26

E.g: Output corrupted with probability 0.25

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of features

Test accuracy for different input sizes

26

The error bars are generated by running the same experiment multiple times for the same setting The data is noisy. And we have all 2n examples.

slide-27
SLIDE 27

E.g: Output corrupted with probability 0.25

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of features

Test accuracy for different input sizes

27

Error = approx 0.375 We can analytically compute test error in this case Correct prediction: P(Training example uncorrupted AND test example uncorrupted) = 0.75 £ 0.75 P(Training example corrupted AND test example corrupted) = 0.25 £ 0.25 P(Correct prediction) = 0.625 Incorrect prediction: P(Training example uncorrupted AND test example corrupted) = 0.75 £ 0.25 P(Training example corrupted and AND example uncorrupted) = 0.25 £ 0.75 P(incorrect prediction) = 0.375 The data is noisy. And we have all 2n examples.

slide-28
SLIDE 28

E.g: Output corrupted with probability 0.25

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of features

Test accuracy for different input sizes

28

What about the training accuracy?

The data is noisy. And we have all 2n examples.

slide-29
SLIDE 29

E.g: Output corrupted with probability 0.25

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of features

Test accuracy for different input sizes

29

What about the training accuracy? Training accuracy = 100% Because the learning algorithm will find a tree that agrees with the data

The data is noisy. And we have all 2n examples.

slide-30
SLIDE 30

E.g: Output corrupted with probability 0.25

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of features

Test accuracy for different input sizes

30

Then, why is the classifier not perfect?

The data is noisy. And we have all 2n examples.

slide-31
SLIDE 31

E.g: Output corrupted with probability 0.25

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of features

Test accuracy for different input sizes

31

Then, why is the classifier not perfect? The classifier overfits the training data

The data is noisy. And we have all 2n examples.

slide-32
SLIDE 32

Overfitting

  • The learning algorithm finds a hypothesis that fits

the noise in the data

– Irrelevant attributes or noisy examples influence the choice of the hypothesis

  • May lead to poor performance on future examples

32

slide-33
SLIDE 33

Overfitting: One definition

  • Data comes from a probability distribution 𝐸(𝑌, 𝑍)
  • We are using a hypothesis space 𝐼
  • Errors:

– Training error for hypothesis ℎ ∈ 𝐼: error!"#$%(ℎ) – True error for ℎ ∈ 𝐼: error&(ℎ)

  • A hypothesis ℎ overfits the training data if there is

another hypothesis ℎ! such that

1. error!"#$% ℎ < error!"#$% ℎ' 2. error& ℎ > error& ℎ'

33

slide-34
SLIDE 34

Overfitting: One definition

  • Data comes from a probability distribution 𝐸(𝑌, 𝑍)
  • We are using a hypothesis space 𝐼
  • Errors:

– Training error for hypothesis ℎ ∈ 𝐼: error!"#$%(ℎ) – True error for ℎ ∈ 𝐼: error&(ℎ)

  • A hypothesis ℎ overfits the training data if there is

another hypothesis ℎ! such that

1. error!"#$% ℎ < error!"#$% ℎ' 2. error& ℎ > error& ℎ'

34

  • 1. ℎ has lower training error than the competing hypothesis ℎ′ but,
  • 2. ℎ′ generalizes better than ℎ.
slide-35
SLIDE 35

Overfitting: One definition

  • Data comes from a probability distribution 𝐸(𝑌, 𝑍)
  • We are using a hypothesis space 𝐼
  • Errors:

– Training error for hypothesis ℎ ∈ 𝐼: error!"#$%(ℎ) – True error for ℎ ∈ 𝐼: error&(ℎ)

  • A hypothesis ℎ overfits the training data if there is

another hypothesis ℎ! such that

1. error!"#$% ℎ < error!"#$% ℎ' 2. error& ℎ > error& ℎ'

35

  • 2. ℎ′ generalizes better than ℎ.
slide-36
SLIDE 36

Overfitting: One definition

  • Data comes from a probability distribution 𝐸(𝑌, 𝑍)
  • We are using a hypothesis space 𝐼
  • Errors:

– Training error for hypothesis ℎ ∈ 𝐼: error!"#$%(ℎ) – True error for ℎ ∈ 𝐼: error&(ℎ)

  • A hypothesis ℎ overfits the training data if there is

another hypothesis ℎ! such that

1. error!"#$% ℎ < error!"#$% ℎ' 2. error& ℎ > error& ℎ'

36

slide-37
SLIDE 37

Decision trees will overfit

37

Plot from Mitchell

slide-38
SLIDE 38

Avoiding overfitting with decision trees

Occam’s Razor

Favor simpler (in this case, shorter) hypotheses Why? Fewer shorter trees, less likely to fit better by coincidence

  • Some approaches:

1. Fix the depth of the tree

  • Decision stump = a decision tree with only one level
  • Typically will not be very good by itself
  • But, we will revisit decision stumps later (short decision trees can make

very good features for a second layer of learning)

38

slide-39
SLIDE 39

Avoiding overfitting with decision trees

Occam’s Razor

Favor simpler (in this case, shorter) hypotheses Why? Fewer shorter trees, less likely to fit better by coincidence

  • Some approaches:

2. Optimize on a held-out set (also called development set or validation set) while growing the trees

  • Split your data into two parts –training set and held-out set
  • Grow your tree on the training split and check the performance on the

held-out set after every new node is added

  • If growing the tree hurts validation set performance, stop growing

39

slide-40
SLIDE 40

Avoiding overfitting with decision trees

Occam’s Razor

Favor simpler (in this case, shorter) hypotheses Why? Fewer shorter trees, less likely to fit better by coincidence

  • Some approaches:

3. Grow full tree and then prune as a post-processing step in one of several ways:

1. Use a validation set for pruning from bottom up greedily 2. Convert the tree into a set of rules (one rule per path from root to leaf) and prune each rule independently

40

slide-41
SLIDE 41

Summary: Decision trees

  • A popular machine learning tool

– Prediction is easy – If we have Boolean features and binary classification, decision trees can represent any Boolean function

  • Greedy heuristics for learning

– ID3 algorithm (using information gain) – Robust implementations of some variants (eg. C4.5 algorithm) exist

  • Can be used for regression too
  • Decision trees are prone to overfitting unless you take care to

avoid it

41