D ECISION T REES Jianping Fan Dept of Computer Science UNC-Charlotte.

Slides:



Advertisements
Similar presentations
Huffman code and ID3 Prof. Sin-Min Lee Department of Computer Science.
Advertisements

Decision Tree Approach in Data Mining
Introduction Training Complexity, Pruning CART vs. ID3 vs. C4.5
Decision Tree Algorithm (C4.5)
Classification Techniques: Decision Tree Learning
Chapter 7 – Classification and Regression Trees
Chapter 7 – Classification and Regression Trees
Decision Trees Instructor: Qiang Yang Hong Kong University of Science and Technology Thanks: Eibe Frank and Jiawei Han.
Decision Tree Algorithm
Induction of Decision Trees Blaž Zupan, Ivan Bratko magix.fri.uni-lj.si/predavanja/uisp.
1 Classification with Decision Trees Instructor: Qiang Yang Hong Kong University of Science and Technology Thanks: Eibe Frank and Jiawei.
Classification: Decision Trees
Induction of Decision Trees
Decision Trees and Decision Tree Learning Philipp Kärger
1 Classification with Decision Trees I Instructor: Qiang Yang Hong Kong University of Science and Technology Thanks: Eibe Frank and Jiawei.
Lecture 5 (Classification with Decision Trees)
Decision Trees an Introduction.
Classification and Prediction by Yen-Hsien Lee Department of Information Management College of Management National Sun Yat-Sen University March 4, 2003.
Classification.
Mehdi Ghayoumi MSB rm 132 Ofc hr: Thur, a Machine Learning.
Classification: Decision Trees 2 Outline  Top-Down Decision Tree Construction  Choosing the Splitting Attribute  Information Gain and Gain Ratio.
Machine Learning Lecture 10 Decision Trees G53MLE Machine Learning Dr Guoping Qiu1.
Learning Chapter 18 and Parts of Chapter 20
Chapter 7 Decision Tree.
ID3 Algorithm Allan Neymark CS157B – Spring 2007.
Business Intelligence Technologies – Data Mining
Induction of Decision Trees Blaž Zupan and Ivan Bratko magix.fri.uni-lj.si/predavanja/uisp.
Fall 2004 TDIDT Learning CS478 - Machine Learning.
Machine Learning Chapter 3. Decision Tree Learning
Learning what questions to ask. 8/29/03Decision Trees2  Job is to build a tree that represents a series of questions that the classifier will ask of.
Induction of Decision Trees. An Example Data Set and Decision Tree yes no yesno sunnyrainy no med yes smallbig outlook company sailboat.
Chapter 9 – Classification and Regression Trees
Lecture 7. Outline 1. Overview of Classification and Decision Tree 2. Algorithm to build Decision Tree 3. Formula to measure information 4. Weka, data.
1 Learning Chapter 18 and Parts of Chapter 20 AI systems are complex and may have many parameters. It is impractical and often impossible to encode all.
Data Mining Practical Machine Learning Tools and Techniques Chapter 4: Algorithms: The Basic Methods Section 4.3: Decision Trees Rodney Nielsen Many of.
For Wednesday No reading Homework: –Chapter 18, exercise 6.
CS690L Data Mining: Classification
For Monday No new reading Homework: –Chapter 18, exercises 3 and 4.
Decision Trees Binary output – easily extendible to multiple output classes. Takes a set of attributes for a given situation or object and outputs a yes/no.
Decision Trees, Part 1 Reading: Textbook, Chapter 6.
Machine Learning Decision Trees. E. Keogh, UC Riverside Decision Tree Classifier Ross Quinlan Antenna Length Abdomen Length.
Presentation on Decision trees Presented to: Sir Marooof Pasha.
Decision Trees.
Machine Learning Recitation 8 Oct 21, 2009 Oznur Tastan.
Decision Trees by Muhammad Owais Zahid
DATA MINING TECHNIQUES (DECISION TREES ) Presented by: Shweta Ghate MIT College OF Engineering.
Data Mining Chapter 4 Algorithms: The Basic Methods - Constructing decision trees Reporter: Yuen-Kuei Hsueh Date: 2008/7/24.
Review of Decision Tree Learning Bamshad Mobasher DePaul University Bamshad Mobasher DePaul University.
Induction of Decision Trees Blaž Zupan and Ivan Bratko magix.fri.uni-lj.si/predavanja/uisp.
Induction of Decision Trees
DECISION TREES An internal node represents a test on an attribute.
Decision Trees an introduction.
Induction of Decision Trees
Classification Algorithms
Artificial Intelligence
Ch9: Decision Trees 9.1 Introduction A decision tree:
Data Science Algorithms: The Basic Methods
Decision Tree Saed Sayad 9/21/2018.
Classification and Prediction
ID3 Algorithm.
Jianping Fan Dept of Computer Science UNC-Charlotte
Machine Learning: Lecture 3
Induction of Decision Trees and ID3
Induction of Decision Trees
Learning Chapter 18 and Parts of Chapter 20
Data Mining(中国人民大学) Yang qiang(香港科技大学) Han jia wei(UIUC)
Learning Chapter 18 and Parts of Chapter 20
Decision Trees Jeff Storey.
Data Mining CSCI 307, Spring 2019 Lecture 15
Presentation transcript:

D ECISION T REES Jianping Fan Dept of Computer Science UNC-Charlotte

T HE PROBLEM OF C LASSIFICATION Given a set of training cases/objects and their attribute values, try to determine the target attribute value of new examples. Classification Prediction

O VERVIEW What is a Decision Tree Sample Decision Trees How to Construct a Decision Tree Problems with Decision Trees Summary

Decision tree is a classifier in the form of a tree structure – Decision node: specifies a test on a single attribute – Leaf node: indicates the value of the target attribute – Arc/edge: split of one attribute – Path: a disjunction of test to make the final decision Decision trees classify instances or examples by starting at the root of the tree and moving through it until a leaf node. D EFINITION

W HY DECISION TREE ? Decision trees are powerful and popular tools for classification and prediction. Decision trees represent rules, which can be understood by humans and used in knowledge system such as database.

KEY REQUIREMENTS Attribute-value description: object or case must be expressible in terms of a fixed collection of properties or attributes (e.g., hot, mild, cold). Predefined classes (target values): the target function has discrete output values (binary or multiclass) Sufficient data: enough training cases should be provided to learn the model.

A N E XAMPLE D ATA S ET AND D ECISION T REE yes no yesno sunnyrainy no med yes smallbig outlook company sailboat

C LASSIFICATION yes no yesno sunnyrainy no med yes smallbig outlook company sailboat

9 DECISION TREE An internal node is a test on an attribute. A branch represents an outcome of the test, e.g., Color=red. A leaf node represents a class label or class label distribution. At each node, one attribute is chosen to split training examples into distinct classes as much as possible A new case is classified by following a matching path to a leaf node.

10 D ECISION T REE C ONSTRUCTION Top-Down Decision Tree Construction Choosing the Splitting Attribute Information Gain and Gain Ratio

P ROSTATE CANCER RECURRENCE Secondary Gleason Grade No Yes PSA Level Stage Primary Gleason Grade No Yes No Yes 1,2345  14.9  14.9 T1c,T2a, T2b,T2c T1ab,T3 2,3 4

A NOTHER E XAMPLE

S IMPLE T REE Outlook HumidityWindyP sunny overcast rainy PN highnormal PN yesno Decision Tree can select different attributes for different decisions!

C OMPLICATED T REE Temperature OutlookWindy cold moderate hot P sunnyrainy N yesno P overcast Outlook sunnyrainy P overcast Windy PN yesno Windy NP yesno Humidity P highnormal Windy PN yesno Humidity P highnormal Outlook N sunnyrainy P overcast null

A TTRIBUTE S ELECTION C RITERIA Main principle Select attribute which partitions the learning set into subsets as “pure” as possible Various measures of purity Information-theoretic Gini index X 2 ReliefF... Various improvements probability estimates normalization binarization, subsetting

16 * W ISH LIST 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 a function that satisfies all three properties! witten&eibe

17 * P ROPERTIES OF THE ENTROPY The multistage property: Simplification of computation: Note: instead of maximizing info gain we could just minimize information witten&eibe

I NFORMATION -T HEORETIC A PPROACH To classify an object, a certain information is needed I, information After we have learned the value of attribute A, we only need some remaining amount of information to classify the object Ires, residual information Gain Gain(A) = I – Ires(A) The most ‘informative’ attribute is the one that minimizes Ires, i.e., maximizes Gain

E NTROPY The average amount of information I needed to classify an object is given by the entropy measure For a two-class problem: entropy p(c1)

R ESIDUAL I NFORMATION After applying attribute A, S is partitioned into subsets according to values v of A Ires is equal to weighted sum of the amounts of information for the subsets

T RIANGLES AND S QUARES

Data Set: A set of classified objects

E NTROPY 5 triangles 9 squares class probabilities entropy......

E NTROPY REDUCTION BY DATA SET PARTITIONING Color? red yellow green

E NTROPIJA VREDNOSTI ATRIBUTA Color? red yellow green

I NFORMATION G AIN Color? red yellow green

I NFORMATION G AIN OF T HE A TTRIBUTE Attributes Gain(Color) = Gain(Outline) = Gain(Dot) = Heuristics: attribute with the highest gain is chosen This heuristics is local (local minimization of impurity)

Color? red yellow green Gain(Outline) = – 0 = bits Gain(Dot) = – = bits

Color? red yellow green.. Outline? dashed solid Gain(Outline) = – = bits Gain(Dot) = – 0 = bits

Color? red yellow green.. dashed solid Dot? no yes.. Outline?

D ECISION T REE Color DotOutlinesquare red yellow green squaretriangle yesno squaretriangle dashedsolid......

A D EFECT OF I RES Ires favors attributes with many values Such attribute splits S to many subsets, and if these are small, they will tend to be pure anyway One way to rectify this is through a corrected measure of information gain ratio.

I NFORMATION G AIN R ATIO I(A) is amount of information needed to determine the value of an attribute A Information gain ratio

I NFORMATION G AIN R ATIO Color? red yellow green

I NFORMATION G AIN AND I NFORMATION G AIN R ATIO

G INI I NDEX Another sensible measure of impurity (i and j are classes) After applying attribute A, the resulting Gini index is Gini can be interpreted as expected error rate

G INI I NDEX......

G INI I NDEX FOR C OLOR Color? red yellow green

G AIN OF G INI I NDEX

40 Shall I play tennis today?

41

42

43

44 How do we choose the best attribute? What should that attribute do for us?

45 W HICH ATTRIBUTE TO SELECT ? witten&eibe

46 C RITERION FOR ATTRIBUTE SELECTION Which is the best attribute? The one which will result in the smallest tree Heuristic: choose the attribute that produces the “ purest ” nodes Need a good measure of purity! Maximal when? Minimal when?

47 I NFORMATION G AIN Which test is more informative? Split over whether Balance exceeds 50K Over 50KLess or equal 50K Employed Unemployed Split over whether applicant is employed

48 I NFORMATION G AIN Impurity/Entropy (informal) Measures the level of impurity in a group of examples

49 I MPURITY Very impure group Less impure Minimum impurity

50 Entropy: a common way to measure impurity Entropy = p i is the probability of class i Compute it as the proportion of class i in the set. Entropy comes from information theory. The higher the entropy the more the information content. What does that mean for learning from examples?

51 2-Class Cases: What is the entropy of a group in which all examples belong to the same class? –entropy = - 1 log 2 1 = 0 What is the entropy of a group with 50% in either class? –entropy = -0.5 log – 0.5 log =1 Minimum impurity Maximum impurity not a good training set for learning good training set for learning

52 I NFORMATION G AIN We want to determine which attribute in a given set of training feature vectors is most useful for discriminating between the classes to be learned. Information gain tells us how important a given attribute of the feature vectors is. We will use it to decide the ordering of attributes in the nodes of a decision tree.

53 Calculating Information Gain Entire population (30 instances) 17 instances 13 instances (Weighted) Average Entropy of Children = Information Gain= = 0.38 Information Gain = entropy(parent) – [average entropy(children)] parent entropy child entropy child entropy

54 E NTROPY -B ASED A UTOMATIC D ECISION T REE C ONSTRUCTION Node 1 What feature should be used? What values? Training Set S x1=(f11,f12,…f1m) x2=(f21,f22, f2m). xn=(fn1,f22, f2m) Quinlan suggested information gain in his ID3 system and later the gain ratio, both based on entropy.

55 U SING I NFORMATION G AIN TO C ONSTRUCT A D ECISION T REE Attribute A v1vk v2 Full Training Set S Set S repeat recursively till when? Information gain has the disadvantage that it prefers attributes with large number of values that split the data into small, pure subsets. Quinlan’s gain ratio did some normalization to improve this. S={s  S | value(A)=v1} Choose the attribute A with highest information gain for the full training set at the root of the tree. Construct child nodes for each value of A. Each has an associated subset of vectors in which A has a particular value.

56 I NFORMATION C ONTENT The information content I(C;F) of the class variable C with possible values {c1, c2, … cm} with respect to the feature variable F with possible values {f1, f2, …, fd} is defined by: P(C = c i ) is the probability of class C having value c i. P(F=f j ) is the probability of feature F having value f j. P(C=c i,F=f j ) is the joint probability of class C = c i and variable F = f j. These are estimated from frequencies in the training data.

57 S IMPLE E XAMPLE Sample Example X Y Z C I I II II How would you distinguish class I from class II?

58 E XAMPLE ( CONT ) Which attribute is best? Which is worst? Does it make sense? X Y Z C I I II II

59 U SING I NFORMATION C ONTENT Start with the root of the decision tree and the whole training set. Compute I(C,F) for each feature F. Choose the feature F with highest information content for the root node. Create branches for each value f of F. On each branch, create a new node with reduced training set and repeat recursively.

60

61

E XAMPLE : T HE S IMPSONS

Person Hair Length WeightAgeClass Homer0”25036M Marge10”15034F Bart2”9010M Lisa6”788F Maggie4”201F Abe1”17070M Selma8”16041F Otto10”18038M Krusty6”20045M Comic8”29038?

Hair Length <= 5? yes no Entropy(4F,5M) = -(4/9)log 2 (4/9) - (5/9)log 2 (5/9) = Entropy(1F,3M) = -(1/4)log 2 (1/4) - (3/4)log 2 (3/4) = Entropy(3F,2M) = -(3/5)log 2 (3/5) - (2/5)log 2 (2/5) = Gain(Hair Length <= 5) = – (4/9 * /9 * ) = Let us try splitting on Hair length

Weight <= 160? yes no Entropy(4F,5M) = -(4/9)log 2 (4/9) - (5/9)log 2 (5/9) = Entropy(4F,1M) = -(4/5)log 2 (4/5) - (1/5)log 2 (1/5) = Entropy(0F,4M) = -(0/4)log 2 (0/4) - (4/4)log 2 (4/4) = 0 Gain(Weight <= 160) = – (5/9 * /9 * 0 ) = Let us try splitting on Weight

age <= 40? yes no Entropy(4F,5M) = -(4/9)log 2 (4/9) - (5/9)log 2 (5/9) = Entropy(3F,3M) = -(3/6)log 2 (3/6) - (3/6)log 2 (3/6) = 1 Entropy(1F,2M) = -(1/3)log 2 (1/3) - (2/3)log 2 (2/3) = Gain(Age <= 40) = – (6/9 * 1 + 3/9 * ) = Let us try splitting on Age

Weight <= 160? yes no Hair Length <= 2? yes no Of the 3 features we had, Weight was best. But while people who weigh over 160 are perfectly classified (as males), the under 160 people are not perfectly classified… So we simply recurse! This time we find that we can split on Hair length, and we are done!

Weight <= 160? yesno Hair Length <= 2? yes no We need don’t need to keep the data around, just the test conditions. Male Female How would these people be classified?

It is trivial to convert Decision Trees to rules… Weight <= 160? yesno Hair Length <= 2? yes no Male Female Rules to Classify Males/Females If Weight greater than 160, classify as Male Elseif Hair Length less than or equal to 2, classify as Male Else classify as Female Rules to Classify Males/Females If Weight greater than 160, classify as Male Elseif Hair Length less than or equal to 2, classify as Male Else classify as Female

70 B UILDING D ECISION T REE [Q93] Top-down tree construction At start, all training examples are at the root. Partition the examples recursively by choosing one attribute each time. Bottom-up tree pruning Remove subtrees or branches, in a bottom-up manner, to improve the estimated accuracy on new cases.

71 T OP -D OWN A PPROACH Top-Down Decision Tree Construction Choosing the Splitting Attribute Information Gain biased towards attributes with a large number of values Gain Ratio takes number and size of branches into account when choosing an attribute

72 C HOOSING THE S PLITTING A TTRIBUTE At each node, available attributes are evaluated on the basis of separating the classes of the training examples. A Goodness function is used for this purpose. Typical goodness functions: information gain (ID3/C4.5) information gain ratio gini index witten&eibe

73 A CRITERION FOR ATTRIBUTE SELECTION Which is the best attribute? The one which will result in the smallest tree Heuristic: choose the attribute that produces the “purest” nodes Popular impurity criterion : information gain Information gain increases with the average purity of the subsets that an attribute produces Strategy: choose attribute that results in greatest information gain witten&eibe

74 C OMPUTING INFORMATION Information is measured in bits Given a probability distribution, the info required to predict an event is the distribution’s entropy Entropy gives the information required in bits (this can involve fractions of bits!) Formula for computing the entropy: witten&eibe

E VALUATION Training accuracy How many training instances can be correctly classify based on the available data? Is high when the tree is deep/large, or when there is less confliction in the training instances. however, higher training accuracy does not mean good generalization Testing accuracy Given a number of new instances, how many of them can we correctly classify? Cross validation

S TRENGTHS can generate understandable rules perform classification without much computation can handle continuous and categorical variables provide a clear indication of which fields are most important for prediction or classification

W EAKNESS Not suitable for prediction of continuous attribute. Perform poorly with many class and small data. Computationally expensive to train. At each node, each candidate splitting field must be sorted before its best split can be found. In some algorithms, combinations of fields are used and a search must be made for optimal combining weights. Pruning algorithms can also be expensive since many candidate sub-trees must be formed and compared. Do not treat well non-rectangular regions.

S UMMARY Decision trees can be used to help predict the future The trees are easy to understand Decision trees work more efficiently with discrete attributes The trees may suffer from error propagation