310 likes | 359 Vues
Decision Trees. Classification Continued Dr Eamonn Keogh Computer Science & Engineering Department University of California - Riverside Riverside,CA 92521 eamonn@cs.ucr.edu. Lets review the classification techniques we have seen so far, in terms of decision surfaces. 5. 4. 3. 2. 1. 0.
E N D
Decision Trees Classification Continued Dr Eamonn Keogh Computer Science & Engineering DepartmentUniversity of California - RiversideRiverside,CA 92521eamonn@cs.ucr.edu
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 2 3 4 5 6 7
5 4 3 2 1 0 -1 Linear Classifier -2 -3 -3 -2 -1 0 1 2 3 4 5 6 7
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 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 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 Age? <=30 31to40 >40 Student? Yes CreditRating? no yes excellent fair no yes no yes Joe, a 25 year old lumberjack with medium income and a fair credit rating. ?, <=30, medium, no, fair
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
10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 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. We want to find the single best rule of the form ifsomefeature > somevaluethen class = sick else class = healthy ifblood sugar > 3.5then class = sick else class = healthy
10 9 8 Blood Sugar > 3.5? 7 6 5 no yes 4 3 Healthy sick 2 1 1 2 3 4 5 6 7 8 9 10
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 continuous attributes. How do we choose a splitting criteria for nominal or Boolean attributes? We want to find the single best rule of the form ifsomefeature=somevaluethen class = sick else class = healthy M Gender F Height
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.
Weight <=30 31 40 >40 to Blood PH < 7? Yes Height > 178? no yes no yes no yes no Blood PH < 5? no yes no What happens if we run out of features to test before correctly partitioning the test set? • 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). • Most items are classified, but 28 individuals remain unclassified after using all features... 18 no 10 yes 18 healthy 12 sick
10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 10 9 Feature Generation Weight BMI Height BMI=kg/m2
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 10100010101010101010101010101010110101…. A 11010101001010101000101010100101010101…. B 10100010101010101010101010101010101111…. B 10100101010101001100111010101010101010…. A 11110101010111101000111010101010111010….
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 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 as0
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)log2(9/14) - (5/14)log2(5/14) = 0.940 Entropy(9 ,0 ) = -(9/9)log2(9/9) - (0/9)log2(0/9) = 0 Entropy(0 ,5 ) = -(0/5)log2(0/5) - (5/5)log2(5/5) = 0 log(1) = 0
Entropy(9 ,5 ) ( Entropy(9 ,0 ) Entropy(0 ,5 ) ) - + Gain(A) = = 0.940 log(1) = 0
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) 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 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
5 4 3 2 1 0 Nearest Neighbor Classifier -1 -2 -3 7 -3 -2 -1 0 1 2 3 4 5 6