Download presentation

Presentation is loading. Please wait.

Published byGenesis Tolles Modified about 1 year ago

1
Data Mining Classification This lecture node is modified based on Lecture Notes for Chapter 4/5 of Introduction to Data Mining by Tan, Steinbach, Kumar, and slides from Jiawei Han for the book of Data Mining – Concepts and Techniqies by Jiawei Han and Micheline Kamber. © Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 1

2
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Classification: Definition l Given a collection of records (training set ) –Each record contains a set of attributes, one of the attributes is the class. l Find a model for class attribute as a function of the values of other attributes. l Goal: previously unseen records should be assigned a class as accurately as possible. –A test set is used to determine the accuracy of the model. Usually, the given data set is divided into training and test sets, with training set used to build the model and test set used to validate it.

3
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Classification Techniques l Decision Tree l Naïve Bayes l kNN Classification

4
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Decision Tree Classification Task Decision Tree

5
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Example of a Decision Tree categorical continuous class Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Splitting Attributes Training Data Model: Decision Tree

6
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Another Example of Decision Tree categorical continuous class MarSt Refund TaxInc YES NO Yes No Married Single, Divorced < 80K> 80K There could be more than one tree that fits the same data! Tid RefundMarital Status Taxable Income Cheat 1YesSingle125K No 2 Married100K No 3 Single70K No 4YesMarried120K No 5 Divorced95K Yes 6NoMarried60K No 7YesDivorced220K No 8 Single85K Yes 9NoMarried75K No 10NoSingle90K Yes 10

7
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Decision Tree Classification Task Decision Tree

8
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data Start from the root of tree.

9
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

10
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

11
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

12
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

13
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data Assign Cheat to “No”

14
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Performance Metrics PREDICTED CLASS ACTUAL CLASS Class=YesClass=No Class=Yesa (TP) b (FN) Class=Noc (FP) d (TN) FNFPTNTP TNTP dcba da Accuracy

15
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ General Structure of Hunt’s Algorithm l Let D t be the set of training records that reach a node t l General Procedure: –If D t contains records that belong the same class y t, then t is a leaf node labeled as y t –If D t is an empty set, then t is a leaf node labeled by the default class, y d –If D t contains records that belong to more than one class, use an attribute test to split the data into smaller subsets. Recursively apply the procedure to each subset. DtDt ?

16
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Hunt’s Algorithm Don’t Cheat Refund Don’t Cheat Don’t Cheat YesNo Refund Don’t Cheat YesNo Marital Status Don’t Cheat Single, Divorced Married Taxable Income Don’t Cheat < 80K>= 80K Refund Don’t Cheat YesNo Marital Status Don’t Cheat Single, Divorced Married

17
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Tree Induction l Greedy strategy. –Split the records based on an attribute test that optimizes certain criterion. l Issues –Determine how to split the records How to specify the attribute test condition? How to determine the best split? –Determine when to stop splitting

18
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ How to determine the Best Split Before Splitting: 10 records of class 0, 10 records of class 1 Which test condition is the best?

19
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ How to determine the Best Split l Greedy approach: –Nodes with homogeneous class distribution are preferred l Need a measure of node impurity: Non-homogeneous, High degree of impurity Homogeneous, Low degree of impurity

20
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ How to Find the Best Split B? YesNo Node N3Node N4 A? YesNo Node N1Node N2 Before Splitting: M0 M1 M2M3M4 M12 M34 Gain = M0 – M12 vs M0 – M34

21
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Measure of Impurity: GINI l Gini Index for a given node t : (NOTE: p( j | t) is the relative frequency of class j at node t). –Maximum when records are equally distributed among all classes, implying least interesting information –Minimum (0.0) when all records belong to one class, implying most interesting information

22
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Examples for computing GINI P(C1) = 0/6 = 0 P(C2) = 6/6 = 1 Gini = 1 – P(C1) 2 – P(C2) 2 = 1 – 0 – 1 = 0 P(C1) = 1/6 P(C2) = 5/6 Gini = 1 – (1/6) 2 – (5/6) 2 = P(C1) = 2/6 P(C2) = 4/6 Gini = 1 – (2/6) 2 – (4/6) 2 = 0.444

23
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Splitting Based on GINI l When a node p is split into k partitions (children), the quality of split is computed as, where,n i = number of records at child i, n = number of records at node p.

24
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Binary Attributes: Computing GINI Index l Split into two partitions l Effect of weighing partitions: –Larger and Purer Partitions are sought for. B? YesNo Node N1Node N2 Gini(N1) = 1 – (5/7) 2 – (2/7) 2 = Gini(N2) = 1 – (1/5) 2 – (4/5) 2 = Gini(Children) = 7/12 * /12 * = 0.371

25
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Categorical Attributes: Computing Gini Index l For each distinct value, gather counts for each class in the dataset l Use the count matrix to make decisions Multi-way splitTwo-way split (find best partition of values)

26
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Continuous Attributes: Computing Gini Index l Use Binary Decisions based on one value l Several Choices for the splitting value –Number of possible splitting values = Number of distinct values l Each splitting value has a count matrix associated with it –Class counts in each of the partitions, A < v and A v l Simple method to choose best v –For each v, scan the database to gather count matrix and compute its Gini index –Computationally Inefficient! Repetition of work.

27
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Alternative Splitting Criteria based on INFO l Entropy at a given node t: (NOTE: p( j | t) is the relative frequency of class j at node t). –Measures homogeneity of a node. Maximum when records are equally distributed among all classes implying least information Minimum (0.0) when all records belong to one class, implying most information –Entropy based computations are similar to the GINI index computations

28
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Examples for computing Entropy P(C1) = 0/6 = 0 P(C2) = 6/6 = 1 Entropy = – 0 log 0 – 1 log 1 = – 0 – 0 = 0 P(C1) = 1/6 P(C2) = 5/6 Entropy = – (1/6) log 2 (1/6) – (5/6) log 2 (1/6) = 0.65 P(C1) = 2/6 P(C2) = 4/6 Entropy = – (2/6) log 2 (2/6) – (4/6) log 2 (4/6) = 0.92

29
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Splitting Based on INFO... l Information Gain: Parent Node, p is split into k partitions; n i is number of records in partition i –Measures Reduction in Entropy achieved because of the split. Choose the split that achieves most reduction (maximizes GAIN) –Disadvantage: Tends to prefer splits that result in large number of partitions, each being small but pure.

30
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Splitting Based on INFO... l Gain Ratio: Parent Node, p is split into k partitions n i is the number of records in partition i –Adjusts Information Gain by the entropy of the partitioning (SplitINFO). Higher entropy partitioning (large number of small partitions) is penalized! –Designed to overcome the disadvantage of Information Gain

31
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Splitting Criteria based on Classification Error l Classification error at a node t : l Measures misclassification error made by a node. Maximum when records are equally distributed among all classes, implying least interesting information Minimum (0.0) when all records belong to one class, implying most interesting information

32
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Examples for Computing Error P(C1) = 0/6 = 0 P(C2) = 6/6 = 1 Error = 1 – max (0, 1) = 1 – 1 = 0 P(C1) = 1/6 P(C2) = 5/6 Error = 1 – max (1/6, 5/6) = 1 – 5/6 = 1/6 P(C1) = 2/6 P(C2) = 4/6 Error = 1 – max (2/6, 4/6) = 1 – 4/6 = 1/3

33
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Comparison among Splitting Criteria For a 2-class problem:

34
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Stopping Criteria for Tree Induction l Stop expanding a node when all the records belong to the same class l Stop expanding a node when all the records have similar attribute values l Early termination

35
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Training Dataset This follows an example from Quinlan’s ID3

36
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ More on Information Gain S contains s i tuples of class C i for i = {1, …, m} information measures info required to classify any arbitrary tuple entropy of attribute A with values {a 1,a 2,…,a v } information gained by branching on attribute A

37
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Attribute Selection by Information Gain Class P: buys_computer = “yes” Class N: buys_computer = “no” I(p, n) = I(9, 5) =0.940 Compute the entropy for age: means “age <=30” has 5 out of 14 samples, with 2 yes’es and 3 no’s. Hence Similarly,

38
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Output: A Decision Tree for “buys_computer” age? overcast student?credit rating? noyes fair excellent <=30 >40 no yes

39
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Classification Rules l Represent the knowledge in the form of IF-THEN rules l One rule is created for each path from the root to a leaf l Each attribute-value pair along a path forms a conjunction l The leaf node holds the class prediction l Rules are easier for humans to understand l Example IF age = “<=30” AND student = “no” THEN buys_computer = “no” IF age = “<=30” AND student = “yes” THEN buys_computer = “yes” IF age = “31…40” THEN buys_computer = “yes” IF age = “>40” AND credit_rating = “excellent” THEN buys_computer = “yes” IF age = “<=30” AND credit_rating = “fair” THEN buys_computer = “no”

40
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Decision Tree Based Classification l Advantages: –Inexpensive to construct –Extremely fast at classifying unknown records –Easy to interpret for small-sized trees –Accuracy is comparable to other classification techniques for many simple data sets

41
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Decision Boundary Border line between two neighboring regions of different classes is known as decision boundary Decision boundary is parallel to axes because test condition involves a single attribute at-a-time

42
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Oblique Decision Trees x + y < 1 Class = + Class = Test condition may involve multiple attributes More expressive representation Finding optimal test condition is computationally expensive

43
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Model Underfitting/Overfitting l The errors of a classification model are divided into two types –Training errors: the number of misclassification errors committed on training records. –Generalization errors: the expected error of the model on previously unseen records. l A good model must have both errors low. l Model underfitting: both type of errors are large when the decision tree is too small. l Model overfitting: training error is small but generalization error is large, when the decision tree is too large.

44
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Underfitting and Overfitting (Example) 500 circular and 500 triangular data points. Circular points: 0.5 sqrt(x 1 2 +x 2 2 ) 1 Triangular points: sqrt(x 1 2 +x 2 2 ) > 0.5 or sqrt(x 1 2 +x 2 2 ) < 1

45
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Underfitting and Overfitting Overfitting Underfitting: when model is too simple, both training and test errors are large

46
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ An Example: Training Dataset

47
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ An Example: Testing Dataset

48
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ An Example: Two Models, M1 and M2 0% training error 30% testing error 20% training error 10% testing error (human, warm-blooded, yes, no, no) (dolphin, warm-blooded, yes, no, no) (spiny anteater, warm-blooded, no, yes, yes )

49
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Occam’s Razor l Given two models of similar generalization errors, one should prefer the simpler model over the more complex model l For complex models, there is a greater chance that it was fitted accidentally by errors in data l Therefore, one should include model complexity when evaluating a model

50
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Incorporating Model Complexity (2) l Training errors: error on training ( e(t)) l Generalization errors: error on testing ( e’(t)) l Methods for estimating generalization errors: –Optimistic approach: e’(t) = e(t) –Pessimistic approach: For each leaf node: e’(t) = (e(t)+0.5) Total errors: e’(T) = e(T) + N 0.5 (N: number of leaf nodes) For a tree with 30 leaf nodes and 10 errors on training (out of 1000 instances): Training error = 10/1000 = 1% Generalization error = ( 0.5)/1000 = 2.5%

51
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ An Example: Pessimistic Error Estimate l The generalization error of TL is (4 + 7 * 0.5)/24 = , and the generalization error of TR is (6 + 4 * 0.5)/24 = , where the penalty term is 0.5. l Based on pessimistic error estimate, the TL should be used.

52
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ How to Address Overfitting (1) l Pre-Pruning (Early Stopping Rule) –Stop the algorithm before it becomes a fully-grown tree –Typical stopping conditions for a node: Stop if all instances belong to the same class Stop if all the attribute values are the same –More restrictive conditions: Stop if number of instances is less than some user-specified threshold Stop if class distribution of instances are independent of the available features (e.g., using chi-squared test) Stop if expanding the current node does not improve impurity measures (e.g., Gini or information gain).

53
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ How to Address Overfitting (2) l Post-pruning –Grow decision tree to its entirety –Trim the nodes of the decision tree in a bottom-up fashion –If generalization error improves after trimming, replace sub-tree by a leaf node. –Class label of leaf node is determined from majority class of instances in the sub-tree –Can use MDL (Minimum Description Length) for post-pruning

54
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/ Example of Post-Pruning Class = Yes20 Class = No10 Error = 10/30 Training Error (Before splitting) = 10/30 Pessimistic error = ( )/30 = 10.5/30 Training Error (After splitting) = 9/30 Pessimistic error (After splitting) = (9 + 4 0.5)/30 = 11/30 PRUNE! Class = Yes8 Class = No4 Class = Yes3 Class = No4 Class = Yes4 Class = No1 Class = Yes5 Class = No1

Similar presentations

© 2016 SlidePlayer.com Inc.

All rights reserved.

Ads by Google