Decision Trees Classification Continued Dr Eamonn Keogh Computer

  • Slides: 31
Download presentation
Decision Trees Classification Continued Dr Eamonn Keogh Computer Science & Engineering Department University of

Decision Trees Classification Continued Dr Eamonn Keogh Computer Science & Engineering Department University of California - Riverside, CA 92521 eamonn@cs. ucr. edu

Lets review the classification techniques we have seen so far, in terms of decision

Lets review the classification techniques we have seen so far, in terms of decision surfaces.

5 4 3 2 1 0 -1 -2 -3 -3 -2 -1 0 1

5 4 3 2 1 0 -1 -2 -3 -3 -2 -1 0 1 2 3 4 5 6 7

5 4 3 2 1 0 -1 Linear Classifier -2 -3 -3 -2 -1

5 4 3 2 1 0 -1 Linear Classifier -2 -3 -3 -2 -1 0 1 2 3 4 5 6 7

Nearest Neighbor Classifier

Nearest Neighbor Classifier

4 3 2 1 0 -1 -2 -2 -1 0 1 2 3 4

4 3 2 1 0 -1 -2 -2 -1 0 1 2 3 4 5 6

Decision Tree Classification • Decision tree – – A flow-chart-like tree structure Internal node

Decision Tree Classification • Decision tree – – A flow-chart-like tree structure Internal node denotes a test on an attribute Branch represents an outcome of the test Leaf nodes represent class labels or class distribution • Decision tree generation consists of two phases – Tree construction • At start, all the training examples are at the root • Partition examples recursively based on selected attributes – Tree pruning • Identify and remove branches that reflect noise or outliers • Use of decision tree: Classifying an unknown sample – Test the attribute values of the sample against the decision tree

Decision Tree Example I We have above data in our database, based upon this

Decision Tree Example I We have above data in our database, based upon this data, we want to predict if potential customers are likely to buy a computer. For example: will Joe, a 25 year old lumberjack with medium income and a fair credit rating buy a PC?

Decision Tree Example II Joe, a 25 year old lumberjack with medium income and

Decision Tree Example II Joe, a 25 year old lumberjack with medium income and a fair credit rating. ? , <=30, medium, no, fair Age? <=30 31 to 40 Student? Yes >40 Credit. Rating? no yes excellent fair no yes

How do we construct the decision tree? • Basic algorithm (a greedy algorithm) –

How do we construct the decision tree? • Basic algorithm (a greedy algorithm) – Tree is constructed in a top-down recursive divide-and-conquer manner – At start, all the training examples are at the root – Attributes are categorical (if continuous-valued, they can be discretized in advance) – Examples are partitioned recursively based on selected attributes. – Test attributes are selected on the basis of a heuristic or statistical measure (e. g. , information gain) • Conditions for stopping partitioning – All samples for a given node belong to the same class – There are no remaining attributes for further partitioning – majority voting is employed for classifying the leaf – There are no samples left

Imagine this dataset shows two classes of people, healthy and sick. The X-axis shows

Imagine this dataset shows two classes of people, healthy and sick. The X-axis shows their blood sugar count, the Y axis shows their white cell count. 10 9 8 7 6 5 4 3 2 1 We want to find the single best rule of the form if somefeature > somevalue then class = sick else class = healthy 1 2 3 4 5 6 7 8 9 10 if blood sugar > 3. 5 then class = sick else class = healthy

10 9 8 7 6 5 4 3 2 1 Blood Sugar > 3.

10 9 8 7 6 5 4 3 2 1 Blood Sugar > 3. 5? 1 2 3 4 5 6 7 8 9 10 no yes Healthy sick

10 9 8 7 6 5 4 3 2 1 1 2 3 4

10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10

We have only informally shown how the decision tree chooses the splitting point for

We have only informally shown how the decision tree chooses the splitting point for continuous attributes. We want to find the single best rule of the form if somefeature = somevalue then How do we choose a splitting criteria for nominal or Boolean attributes? Gender class = sick else class = healthy M F Height

Example of a problem that decision trees do poorly on.

Example of a problem that decision trees do poorly on.

We have now seen several classification algorithms. How should we compare them? • Predictive

We have now seen several classification algorithms. How should we compare them? • Predictive accuracy • Speed and scalability – time to construct the model – time to use the model • Robustness – handling noise and missing values • Scalability – efficiency in disk-resident databases • Interpretability: – understanding and insight provided by the model.

What happens if we run out of features to test before correctly partitioning the

What happens if we run out of features to test before correctly partitioning the test set? Weight <=30 31 40 to Blood PH < 7? Yes Here we have a dataset with 3 features. • Weight • Blood PH • Height We are trying to classify people into two classes, yes or no (ie yes, they will get sick or no they won’t). >40 Height > 178? no yes no Blood PH < 5? no no yes 1818 nohealthy 10 yes 12 sick Most items are classified, but 28 individuals remain unclassified after using all features. . .

Weight Feature Generation 10 9 8 7 6 5 4 3 2 1 1

Weight Feature Generation 10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 Height BMI=kg/m 2 1 2 3 4 5 6 7 8 9 10 BMI

Feature Generation Case Study Suppose we have the following two classes. . Class A:

Feature Generation Case Study Suppose we have the following two classes. . Class A: 100 random coin tosses Class B: A human “faking” 100 random coin tosses A 101000101010101010110101…. A 11010101000101010101…. B 101000101010101010101111…. B 1010010101001110101010…. A 111101011110100011101010111010….

What splitting criteria should we use?

What splitting criteria should we use?

How many bits do I need to label all the objects in this box?

How many bits do I need to label all the objects in this box? How many bits do I need to label all the objects in these boxes?

Information Gain as A Splitting Criteria • Select the attribute with the highest information

Information Gain as A Splitting Criteria • Select the attribute with the highest information gain (information gain is the expected reduction in entropy). • Assume there are two classes, P and N – Let the set of examples S contain p elements of class P and n elements of class N – The amount of information, needed to decide if an arbitrary example in S belongs to P or N is defined as 0 log(0) is defined as 0

Information Gain in Decision Tree Induction • Assume that using attribute A, a current

Information Gain in Decision Tree Induction • Assume that using attribute A, a current set will be partitioned into some number of child sets • The encoding information that would be gained by branching on A Note: entropy is at its minimum if the collection of objects is completely uniform

Entropy(9 , 5 ) = -(9/14)log 2(9/14) - (5/14)log 2(5/14) = 0. 940 Entropy(9

Entropy(9 , 5 ) = -(9/14)log 2(9/14) - (5/14)log 2(5/14) = 0. 940 Entropy(9 , 0 ) = -(9/9)log 2(9/9) - (0/9)log 2(0/9) = 0 Entropy(0 , 5 ) = -(0/5)log 2(0/5) - (5/5)log 2(5/5) = 0 log(1) = 0

Gain(A) = Entropy(9 , 5 ) - ( Entropy(9 , 0 ) + Entropy(0

Gain(A) = Entropy(9 , 5 ) - ( Entropy(9 , 0 ) + Entropy(0 , 5 ) ) = 0. 940 log(1) = 0

Avoiding Overfitting in Classification • The generated tree may overfit the training data –

Avoiding Overfitting in Classification • The generated tree may overfit the training data – Too many branches, some may reflect anomalies due to noise or outliers – Result is in poor accuracy for unseen samples • Two approaches to avoid overfitting – Prepruning: Halt tree construction early—do not split a node if this would result in the goodness measure falling below a threshold • Difficult to choose an appropriate threshold – Postpruning: Remove branches from a “fully grown” tree —get a sequence of progressively pruned trees • Use a set of data different from the training data to decide which is the “best pruned tree”

Approaches to Determine the Final Tree Size • Separate training (2/3) and testing (1/3)

Approaches to Determine the Final Tree Size • Separate training (2/3) and testing (1/3) sets • Use cross validation, e. g. , 10 -fold cross validation • Use all the data for training – but apply a statistical test (e. g. , chi-square) to estimate whether expanding or pruning a node may improve the entire distribution

Feature Selection One of the nice features of decision trees is that they automatically

Feature Selection One of the nice features of decision trees is that they automatically discover the best features to use (the ones near the top of the tree), and which features are irrelevant for the problem (the features which are no used). How do we decide which features to use for nearest neighbor, or the linear classifier? Suppose we are trying to decide if tomorrow is a good day to play tennis, based on the temperature, the windspeed, the humidity and the outlook… We could use just the temperature, or just {temperature, windspeed} or just {…} This sounds like a search problem!

 • Forward Selection • Backward Elimination • Bi-directional Search

• Forward Selection • Backward Elimination • Bi-directional Search

5 4 3 2 1 0 -1 -2 -3 -3 -2 -1 0 1

5 4 3 2 1 0 -1 -2 -3 -3 -2 -1 0 1 2 3 4 5 6 7 Nearest Neighbor Classifier