Download presentation

Presentation is loading. Please wait.

Published byEverett Stanley Modified about 1 year ago

1
Data Mining Classification: Basic Concepts, Decision Trees, and Model Evaluation Lecture Notes for Chapter 4 Introduction to Data Mining by Tan, Steinbach, Kumar

2
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Classification: Definition o Given a collection of records (training set ) –Each record contains a set of attributes, one of the attributes is the class. o Find a model for the class attribute as a function of the values of other attributes. o 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 Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Illustrating Classification Task

4
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Examples of Classification Task o Predicting tumor cells as benign or malignant o Classifying credit card transactions as legitimate or fraudulent o Classifying secondary structures of protein as alpha-helix, beta-sheet, or random coil o Categorizing news stories as finance, weather, entertainment, sports, etc

5
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Classification Techniques o Decision Tree based Methods covered in Part1 o Rule-based Methods o Memory based reasoning, instance-based learning covered in Part2 o Neural Networks o Naïve Bayes and Bayesian Belief Networks o Support Vector Machines covered in Part2 o Ensemble Methods covered in Part2

6
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

7
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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!

8
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Lecture Notes for Chapter 4 Introduction to Data Mining by Tan, Steinbach, Kumar Objectives Data Mining Course Goals and Objectives of Data Mining Classification Techniques Association Analysis Clustering Algorithms Exploratory Data Analysis and Preprocessing Apply Data Mining to Real World Datasets Learn How to Interpret Data Mining Results Implementing Data Mining Algorithms Using R for Data Analysis And Data Mining Making Sense of Data

9
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Introduction to Classification: Basic Concepts and Decision Trees Organization 1. Basics 2. Decision Tree Induction Algorithms 3. Overfitting and Underfitting 4. Pruning Techniques 5. Dealing with Missing Values 6. Assessing the Accuracy of Classification Techniques 7. Advantage and Disadvantages of Decision Trees

10
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Decision Tree Classification Task Decision Tree

11
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data Start from the root of tree.

12
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

13
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

14
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

15
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data

16
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Apply Model to Test Data Refund MarSt TaxInc YES NO YesNo Married Single, Divorced < 80K> 80K Test Data Assign Cheat to “No”

17
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Decision Tree Classification Task Decision Tree

18
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Decision Tree Induction o Many Algorithms: –Hunt’s Algorithm (one of the earliest) –CART –ID3, C4.5 –SLIQ,SPRINT

19
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 General Structure of Hunt’s Algorithm o Let D t be the set of training records that reach a node t o 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 ?

20
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

21
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Tree Induction o Greedy strategy –Split the records based on an attribute test that optimizes certain criterion. Remark: Finding optimal decision trees is NP-hard. o Issues 1.Determine how to split the records How to specify the attribute test condition? How to determine the best split? 2.Determine when to stop splitting

22
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Tree Induction o Greedy strategy (http://en.wikipedia.org/wiki/Greedy_algorithm ) Creates the tree top down starting from the root, and splits the records based on an attribute test that optimizes certain criterion.http://en.wikipedia.org/wiki/Greedy_algorithm o 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

23
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Side Discussion “Greedy Algorithms” o Fast and therefore attractive to solve NP-hard and other problems with high complexity. Later decisions are made in the context of decision selected early dramatically reducing the size of the search space. o They do not backtrack: if they make a bad decision (based on local criteria), they never revise the decision. o They are not guaranteed to find the optimal solution(s), and sometimes can get deceived and find really bad solutions. o In spite of what is said above, a lot successful and popular algorithms in Computer Science are greedy algorithms. o Greedy algorithms are particularly popular in AI and Operations Research. o See also: Popular Greedy Algorithms: Decision Tree Induction,…

24
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 How to Specify Test Condition? o Depends on attribute types –Nominal –Ordinal –Continuous o Depends on number of ways to split –2-way split –Multi-way split

25
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Splitting Based on Nominal Attributes o Multi-way split: Use as many partitions as distinct values. o Binary split: Divides values into two subsets. Need to find optimal partitioning. CarType Family Sports Luxury CarType {Family, Luxury} {Sports} CarType {Sports, Luxury} {Family} OR

26
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 o Multi-way split: Use as many partitions as distinct values. o Binary split: Divides values into two subsets. Need to find optimal partitioning. o What about this split? Splitting Based on Ordinal Attributes Size Small Medium Large Size {Medium, Large} {Small} Size {Small, Medium} {Large} OR Size {Small, Large} {Medium}

27
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Splitting Based on Continuous Attributes o Different ways of handling –Discretization to form an ordinal categorical attribute Static – discretize once at the beginning Dynamic – ranges can be found by equal interval bucketing, equal frequency bucketing (percentiles), clustering, or supervised clustering. –Binary Decision: (A < v) or (A v) consider all possible splits and finds the best cut v can be more compute intensive

28
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Splitting Based on Continuous Attributes

29
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Tree Induction o Greedy strategy. –Split the records based on an attribute test that optimizes certain criterion. o 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

30
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 How to determine the Best Split? Before Splitting: 10 records of class 0, 10 records of class 1 Before: E(1/2,1/2) After: 4/20*E(1/4,3/4) + 8/20*E(1,0) + 8/20*(1/8,7/8) Gain: Before-After Pick Test that has the highest gain! Remark: E stands for Gini, H (Entropy), Impurity, …

31
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 How to determine the Best Split o Greedy approach: –Nodes with homogeneous class distribution (pure nodes) are preferred o Need a measure of node impurity: Non-homogeneous, High degree of impurity Homogeneous, Low degree of impurity

32
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Measures of Node Impurity o Gini Index o Entropy o Misclassification error Remark: All three approaches center on selecting tests that maximize purity. They just disagree in how exactly purity is measured.

33
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

34
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Measure of Impurity: GINI o Gini Index for a given node t : (NOTE: p( j | t) is the relative frequency of class j at node t). –Maximum (1 - 1/n c ) 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

35
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

36
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Splitting Based on GINI o Used in CART, SLIQ, SPRINT. o 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.

37
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Binary Attributes: Computing GINI Index o Splits into two partitions o 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 * Gini(N1) + 5/12 * Gini(N2)=y

38
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Categorical Attributes: Computing Gini Index o For each distinct value, gather counts for each class in the dataset o Use the count matrix to make decisions Multi-way splitTwo-way split (find best partition of values)

39
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Continuous Attributes: Computing Gini Index o Use Binary Decisions based on one value o Several Choices for the splitting value –Number of possible splitting values = Number of distinct values o Each splitting value has a count matrix associated with it –Class counts in each of the partitions, A < v and A v o 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.

40
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Continuous Attributes: Computing Gini Index... o For efficient computation: for each attribute, –Sort the attribute on values –Linearly scan these values, each time updating the count matrix and computing gini index –Choose the split position that has the least gini index Split Positions Sorted Values

41
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Alternative Splitting Criteria based on INFO o 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 (log n c ) 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

42
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

43
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Splitting Based on INFO... o 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) –Used in ID3 and C4.5 –Disadvantage: Tends to prefer splits that result in large number of partitions, each being small but pure.

44
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Splitting Based on INFO... o 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! –Used in C4.5 –Designed to overcome the disadvantage of Information Gain

45
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Entropy and Gain Computations Assume we have m classes in our classification problem. A test S subdivides the examples D= (p 1,…,p m ) into n subsets D 1 =(p 11,…,p 1m ),…,D n =(p 11,…,p 1m ). The qualify of S is evaluated using Gain(D,S) (ID3) or GainRatio(D,S) (C5.0): Let H(D=(p 1,…,p m ))= i=1 (p i log 2 (1/p i )) (called the entropy function) Gain(D,S)= H(D) i=1 (|D i |/|D|)*H(D i ) Gain_Ratio(D,S)= Gain(D,S) / H(|D 1 |/|D|,…, |D n |/|D|) Remarks: |D| denotes the number of elements in set D. D=(p 1,…,p m ) implies that p 1 +…+ p m =1 and indicates that of the |D| examples p 1 *|D| examples belong to the first class, p 2 *|D| examples belong to the second class,…, and p m *|D| belong the m-th (last) class. H(0,1)=H(1,0)=0; H(1/2,1/2)=1, H(1/4,1/4,1/4,1/4)=2, H(1/p,…,1/p)=log 2 (p). C5.0 selects the test S with the highest value for Gain_Ratio(D,S), whereas ID3 picks the test S for the examples in set D with the highest value for Gain (D,S). m n

46
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Information Gain vs. Gain Ratio D=(2/3,1/3) D1(1,0)D2(1/3,2/3) D=(2/3,1/3) D1(0,1) D2(2/3,1/3) D3(1,0) D=(2/3,1/3) D1(1,0) D2(0,1) D3(1,0)D4(1,0)D5(1,0) D6(0,1) city=sf city=la car=merccar=taurus car=van age=22 age=25age=27age=35 age=40age=50 Gain(D,city=)= H(1/3,2/3) – ½ H(1,0) – ½ H(1/3,2/3)=0.45 Gain(D,car=)= H(1/3,2/3) – 1/6 H(0,1) – ½ H(2/3,1/3) – 1/3 H(1,0)=0.45 Gain(D,age=)= H(1/3,2/3) – 6*1/6 H(0,1) = 0.90 G_Ratio_pen(city=)=H(1/2,1/2)=1 G_Ratio_pen(age=)=log 2 (6)=2.58 G_Ratio_pen(car=)=H(1/2,1/3,1/6)=1.45 Result: I_Gain_Ratio: city>age>car Result: I_Gain: age > car=city

47
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Splitting Criteria based on Classification Error o Classification error at a node t : o Measures misclassification error made by a node. Maximum (1 - 1/n c ) 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 Comment: same as impurity!

48
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

49
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Comparison among Splitting Criteria For a 2-class problem:

50
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Tree Induction o Greedy strategy. –Split the records based on an attribute test that optimizes certain criterion. o 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

51
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Stopping Criteria for Tree Induction o Stop expanding a node when all the records belong to the same class o Stop expanding a node when all the records have similar attribute values o Early termination (to be discussed later)

52
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Example: C4.5 o Simple depth-first construction. o Uses Information Gain o Sorts Continuous Attributes at each node. o Needs entire data to fit in memory. o One of the Top 10 Data Mining Algorithms (more in December about that!) o Unsuitable for Large Datasets. –Needs out-of-core sorting.

53
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/ Regression Trees Not in textbook!

54
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Summary Regression Trees o Regression trees work as decision trees except –Leafs carry numbers which predict the output variable instead of class label –Instead of entropy/purity the squared prediction error serves as the performance measure. –Tests that reduce the squared prediction error the most are selected as node test; test conditions have the form y>threshold where y is an independent variable of the prediction problem. –Instead of using the majority class, leaf labels are generated by averaging over the values of the dependent variable of the examples that are associated with the particular class node o Like decision trees, regression tree employ rectangular tessellations with a fixed number being associated with each rectangle; the number is the output for the inputs which lie inside the rectangle. o In contrast to ordinary regression that performs curve fitting, regression tries use averaging with respect to the output variable when making predictions. Not in textbook!

55
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Decision and Regression Trees in R o For survey see: o The most popular libraries are: –rpart (the most advanced tree package, based on CART) –tree (the original, more basic package) –maptree / partykit (good for creating graphs) –randomForrest (learns an ensemble of trees instead of a single tree; more competitive as this approach accomplished higher accuracies than single trees) –CORElearn (a very general package that contains trees, forrest, and many other approaches) –Some packages are not compatible; be warned if you use a mixture of packages!

56
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Practical Issues of Classification o Underfitting and Overfitting o Missing Values o Costs of Classification

57
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

58
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Underfitting and Overfitting Overfitting Underfitting: when model is too simple, both training and test errors are large Complexity of a Decision Tree := number of nodes It uses Underfitting Complexity of the classification function Overfitting: when model is too complex and test errors are large although training errors are small.

59
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Overfitting due to Noise Decision boundary is distorted by noise point

60
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Overfitting due to Insufficient Examples Lack of data points in the lower half of the diagram makes it difficult to predict correctly the class labels of that region - Insufficient number of training records in the region causes the decision tree to predict the test examples using other training records that are irrelevant to the classification task

61
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Notes on Overfitting o Overfitting results in decision trees that are more complex than necessary: after learning knowledge they “tend to learn noise” o More complex models tend to have more complicated decision boundaries and tend to be more sensitive to noise, missing examples,… o Training error no longer provides a good estimate of how well the tree will perform on previously unseen records o Need “new” ways for estimating errors

62
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Estimating Generalization Errors o Re-substitution errors: error on training ( e(t) ) o Generalization errors: error on testing ( e’(t)) o 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% –Use validation set to compute generalization error used Reduced error pruning (REP): Regularization approach: Minimize Error + Model Complexity

63
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Occam’s Razor o Given two models of similar generalization errors, one should prefer the simpler model over the more complex model o For complex models, there is a greater chance that it was fitted accidentally by errors in data o Usually, simple models are more robust with respect to noise Therefore, one should include model complexity when evaluating a model

64
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Minimum Description Length (MDL) o Cost(Model,Data) = Cost(Data|Model) + Cost(Model) –Cost is the number of bits needed for encoding. –Search for the least costly model. o Cost(Data|Model) encodes the misclassification errors. o Cost(Model) uses node encoding (number of children) plus splitting condition encoding. Skip today, Read book

65
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 How to Address Overfitting o 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 2 test) Stop if expanding the current node does not improve impurity measures (e.g., Gini or information gain).

66
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 How to Address Overfitting… o 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

67
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

68
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Handling Missing Attribute Values o Missing values affect decision tree construction in three different ways: –Affects how impurity measures are computed –Affects how to distribute instance with missing value to child nodes –Affects how a test instance with missing value is classified

69
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 How to cope with missing values Split on Refund: Entropy(Refund=Yes) = 0 Entropy(Refund=No) = -(2/6)log(2/6) – (4/6)log(4/6) = Entropy(Children) = 0.3 (0) (0.9183) = Gain = 0.9 ( – 0.551) = Missing value Before Splitting: Entropy(Parent) = -0.3 log(0.3)-(0.7)log(0.7) = Idea: ignore examples with null values for the test attribute; compute M(…) only using examples for Which Refund is defined.

70
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Distribute Instances Refund YesNo Refund YesNo Probability that Refund=Yes is 3/9 Probability that Refund=No is 6/9 Assign record to the left child with weight = 3/9 and to the right child with weight = 6/9

71
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Classify Instances Refund MarSt TaxInc YES NO Yes No Married Single, Divorced < 80K> 80K MarriedSingleDivorcedTotal Class=No3104 Class=Yes6/ Total New record: Probability that Marital Status = Married is 3.67/6.67 Probability that Marital Status ={Single,Divorced} is 3/6.67

72
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Other Issues o Data Fragmentation o Search Strategy o Expressiveness o Tree Replication

73
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Data Fragmentation o Number of instances gets smaller as you traverse down the tree o Number of instances at the leaf nodes could be too small to make any statistically significant decision increases the danger of overfitting

74
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Search Strategy o Finding an optimal decision tree is NP-hard o The algorithm presented so far uses a greedy, top-down, recursive partitioning strategy to induce a reasonable solution o Other strategies? –Bottom-up –Bi-directional

75
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Expressiveness o Decision tree provides expressive representation for learning discrete-valued function –But they do not generalize well to certain types of Boolean functions Example: parity function: –Class = 1 if there is an even number of Boolean attributes with truth value = True –Class = 0 if there is an odd number of Boolean attributes with truth value = True For accurate modeling, must have a complete tree o Not expressive enough for modeling continuous variables –Particularly when test condition involves only a single attribute at-a-time

76
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 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

77
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Oblique Decision Trees x + y < 1 Class = + Class = Test condition may involve multiple attributes More expressive representation Finding optimal test condition is computationally expensive

78
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Advantages Decision Tree Based Classification o Inexpensive to construct o Extremely fast at classifying unknown records o Easy to interpret for small-sized trees; strategy understandable to domain expert o Okay for noisy data o Can handle both continuous and symbolic attributes o Accuracy is comparable to other classification techniques for many simple data sets o Decent average performance over many datasets o Can handle multi-modal class distributions o Kind of a standard — if you want to show that your “new” classification technique really “improves the world” compare its performance against decision trees (e.g. C 5.0) using 10-fold cross-validation o Does not need distance functions; only the order of attribute values is important for classification: 0.1,0.2,0.3 and 0.331,0.332, and is the same for a decision tree learner.

79
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Disadvantages Decision Tree Based Classification o Relies on rectangular approximation that might not be good for some dataset o Selecting good learning algorithm parameters (e.g. degree of pruning) is non-trivial; however, some of the competing methods have worth parameter selection problems o Ensemble techniques, support vector machines, and sometimes kNN, and neural networks might obtain higher accuracies for a specific dataset.

80
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Model Evaluation o Metrics for Performance Evaluation –How to evaluate the performance of a model? o Methods for Performance Evaluation –How to obtain reliable estimates? o Methods for Model Comparison –How to compare the relative performance among competing models?

81
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Model Evaluation o Metrics for Performance Evaluation –How to evaluate the performance of a model? o Methods for Performance Evaluation –How to obtain reliable estimates? o Methods for Model Comparison –How to compare the relative performance among competing models?

82
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Metrics for Performance Evaluation o Focus on the predictive capability of a model –Rather than how fast it takes to classify or build models, scalability, etc. o Confusion Matrix: PREDICTED CLASS ACTUAL CLASS Class=YesClass=No Class=Yesab Class=Nocd a: TP (true positive) b: FN (false negative) c: FP (false positive) d: TN (true negative) Important: If there are problems with obtaining a “good” classifier inspect the confusion matrix!

83
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Metrics for Performance Evaluation… o Most widely-used metric: PREDICTED CLASS ACTUAL CLASS Class=YesClass=No Class=Yesa (TP) b (FN) Class=Noc (FP) d (TN)

84
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Limitation of Accuracy o Consider a 2-class problem –Number of Class 0 examples = 9990 –Number of Class 1 examples = 10 o If model predicts everything to be class 0, accuracy is 9990/10000 = 99.9 % –Accuracy is misleading because model does not detect any class 1 example

85
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Cost Matrix PREDICTED CLASS ACTUAL CLASS C(i|j) Class=YesClass=No Class=YesC(Yes|Yes)C(No|Yes) Class=NoC(Yes|No)C(No|No) C(i|j): Cost of misclassifying class j example as class i Skip, possibly discussed in Nov.

86
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Computing Cost of Classification Cost Matrix PREDICTED CLASS ACTUAL CLASS C(i|j) Model M 1 PREDICTED CLASS ACTUAL CLASS Model M 2 PREDICTED CLASS ACTUAL CLASS Accuracy = 80% Cost = 3910 Accuracy = 90% Cost = 4255

87
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Cost vs Accuracy Count PREDICTED CLASS ACTUAL CLASS Class=YesClass=No Class=Yes ab Class=No cd Cost PREDICTED CLASS ACTUAL CLASS Class=YesClass=No Class=Yes pq Class=No qp N = a + b + c + d Accuracy = (a + d)/N Cost = p (a + d) + q (b + c) = p (a + d) + q (N – a – d) = q N – (q – p)(a + d) = N [q – (q-p) (a+d)/N] = N [q – (q-p) Accuracy] Accuracy is proportional to cost if 1. C(Yes|No)=C(No|Yes) = q 2. C(Yes|Yes)=C(No|No) = p

88
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Cost-Sensitive Measures l Precision is biased towards C(Yes|Yes) & C(Yes|No) l Recall is biased towards C(Yes|Yes) & C(No|Yes) l F-measure is biased towards all except C(No|No)

89
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Model Evaluation o Metrics for Performance Evaluation –How to evaluate the performance of a model? o Methods for Performance Evaluation –How to obtain reliable estimates? o Methods for Model Comparison –How to compare the relative performance among competing models?

90
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Methods for Performance Evaluation o How to obtain a reliable estimate of the accuracy of a classifier? o Performance of a model may depend on other factors besides the learning algorithm: –Class distribution –Cost of misclassification –Size of training and test sets

91
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Learning Curve l Learning curve shows how accuracy changes with varying sample size l Requires a sampling schedule for creating learning curve: l Arithmetic sampling (Langley, et al) l Geometric sampling (Provost et al) Effect of small sample size: - Bias in the estimate - Variance of estimate

92
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Methods for Estimating Accuracy o Holdout –Reserve 2/3 for training and 1/3 for testing o Random subsampling –Repeated holdout o Cross validation –Partition data into k disjoint subsets –k-fold: train on k-1 partitions, test on the remaining one –Leave-one-out: k=n o Class stratified k-fold cross validation o Stratified sampling –oversampling vs undersampling Most popular!

93
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Model Evaluation o Metrics for Performance Evaluation –How to evaluate the performance of a model? o Methods for Performance Evaluation –How to obtain reliable estimates? o Methods for Model Comparison –How to compare the relative performance among competing models? To be discussed in Part2!

94
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Test of Significance o Given two models: –Model M1: accuracy = 85%, tested on 30 instances –Model M2: accuracy = 75%, tested on 5000 instances –Test we run independently (“unpaired”) o Can we say M1 is better than M2? –How much confidence can we place on accuracy of M1 and M2? –Can the difference in performance measure be explained as a result of random fluctuations in the test set?

95
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Confidence Interval for Accuracy o Prediction can be regarded as a Bernoulli trial –A Bernoulli trial has 2 possible outcomes –Possible outcomes for prediction: correct or wrong –Collection of Bernoulli trials has a Binomial distribution: x Bin(N, p) x: number of correct predictions e.g: Toss a fair coin 50 times, how many heads would turn up? Expected number of heads = N p = 50 0.5 = 25 o Given x (# of correct predictions) or equivalently, acc=x/N, and N (# of test instances), Can we predict p (true accuracy of model)?

96
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Confidence Interval for Accuracy o For large test sets (N > 30), –acc has a normal distribution with mean p and variance p(1-p)/N o Confidence Interval for p: Area = 1 - Z /2 Z 1- /2

97
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Unpaired Testing: Comparing 2 Models Accuracy Classifer1 Accuracy Classifer2 Z /2 Z 1- /2 If the blue areas do not overlap: one classifier is significantly better than the other one is degree of confidence. Do the Blue Areas Overlap?? acc1 acc2

98
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Confidence Interval for Accuracy o Consider a model that produces an accuracy of 80% when evaluated on 100 test instances: –N=100, acc = 0.8 –Let 1- = 0.95 (95% confidence) –From probability table, Z /2 = Z N p(lower) p(upper)

99
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Comparing Performance of 2 Models o Given two models, say M1 and M2, which is better? –M1 is tested on D1 (size=n1), found error rate = e 1 –M2 is tested on D2 (size=n2), found error rate = e 2 –Assume D1 and D2 are independent (‘unpaired’) –If n 1 and n 2 are sufficiently large, then –Approximate :

100
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Comparing Performance of 2 Models o To test if performance difference is statistically significant: d = e1 – e2 N –d ~ N(d t, t ) where d t is the true difference –Since D1 and D2 are independent, their variance adds up: –At (1- ) confidence level, standard normal distribution

101
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 An Illustrative Example o Given: M1: n1 = 30, e1 = 0.15 M2: n2 = 5000, e2 = 0.25 o d = |e2 – e1| = 0.1 (2-sided unpaired test) o At 95% confidence level, Z /2 =1.96 => Interval contains 0 => difference is not statistically significant

102
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Paired t-Test o The two-sample t-test is used to determine if two population means are equal. The data may either be paired or not paired. For paired t test, the data is dependent, i.e. there is a one- to-one correspondence between the values in the two samples. For example, same subject measured before & after a process change, or same subject measured at different times. For unpaired t test, the sample sizes for the two samples may or may not be equal.

103
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Comparing 2 Algorithms Using the Same Data 1.http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm (t-table)http://www.itl.nist.gov/div898/handbook/eda/section3/eda3672.htm 2.If models are generated on the same test sets D1,D2, …, Dk (e.g., via cross-validation; k-1 “degrees of freedom”; paired t-test) 1.For each set: compute d j = e 1j – e 2j 2.d j has mean d and “variance” t 3.Estimate: 3.If the confidence interval does not contain 0 you can reject the hypothesis that ‘the difference in accuracy/error rate is 0” with confidence , and therefore infer that one of the two methods is significantly better than the other method; if it includes 0, we cannot infer that one method is significantly better. Student’s t-distribution

104
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Paired Tests --- Is One Classifier Better?? Accuracy Differences Between the Two Classifiers Z /2 Z 1- /2 Acc-dif Key Question: Does the blue area include 0? Yes: both classifiers are not significantly different No: One classifier is significantly more accurate

105
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Example1: Comparing Models on the same Data o 2 models M1 and M2 are compared with 4-fold cross validation; M1 accomplishes accuracies of 0.84, 0.82, 0.80, 0.82 and M2 accomplishes accuracies of 0.80, 0.79, 0.75, The average difference is 0.03 and the required confidence level is 90% ( =0.1) 2.35Reject Remark: If we would require 95% of confidence, we obtain 0.03 *3,182, and would not reject the hypothesis.

106
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 An alternative way to compute it! 1.Compute variance for the difference in accuracy 2.Compute t statistics value 3.See if t value is in (- ,-t ,k-1 ) or (t ,k-1, ) 1. Yes, reject null hypothesis: one method is significantly better than the other method 2. No, no method is significantly better t is t ,k-1 distributed if the various measurements of d i are independent

107
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Example1: Comparing Models on the same Data Using t-Statistic o 2 models M1 and M2 are compared with 4-fold cross validation; M1 accomplishes accuracies of 0.84, 0.82, 0.80, 0.82 and M2 accomplishes accuracies of 0.80, 0.79, 0.75, The average difference is 0.03 and the required confidence level is . 2.35<2.77<3.18 reject at confidence level 90%, but do not reject at level 95%

108
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Example2: Comparing Models on the same Data o 2 models M1 and M2 are compared with 4-fold cross validation; M1 accomplishes accuracies of 0.90, 0.82, 0.76, 0.80 and M2 accomplishes accuracies of 0.83, 0.79, 0.79, The average difference d is 0.03 and the required confidence level is 90% ( =0.1) Now we do not reject that the models perform similarly at almost any confidence level! Why??

109
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 Problems with the student t-test for cross validation Type 1 Error: probability of rejecting the null hypothesis, although it is true; in our case, the type 1 error is the probability of concluding one classifier is better, although this is not the case. Type 2 Error: Null hypothesis is not reject, although it should be rejected o In general, if (training set, test set pairs) are independent, the type 1 error of the student t-test is . o In the case of n-fold cross validation the training sets are overlapping and not independent, and therefore the type 1 error is significantly larger than for n-fold cross validation, due to the fact that the variance of accuracy differences between classifiers is underestimated by the student t-test approach. o Consequently, modifications of the student t-test have been proposed, e.g. [Bouckaert&Frank], for n-fold cross validation.

110
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 A modified t-statistics for r runs of k- fold cross-validation [Bouckaert&Frank] 1.Compute variance for r runs of k-fold cross-validation 2.Compute modified t statistics value 3.See if t value is in (- ,-t ,k-1 ) or (t ,k-1, ): 1. Yes, reject null hypothesis: one method is significantly better than the other method 2. No, no method is significantly better Variance of t-variable is increased considering the fact that test- and training sets overlap; n2/n1 is the ratio of test examples over training examples.

111
Tan,Steinbach, Kumar Introduction to Classification (with major additions/modifications by Ch. Eick) 10/1/2012 [Bouckaert&Frank] for Example1 Sqrt(4)=2 is used in the standard t-test whereas here we use a smaller number which corresponds to using a higher variance estimate. Remark: was 2.77 for original t-test Example 1: 1 run of 4-fold cross-validation

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google