Classification: Basic Concepts, Decision Trees, and Model Evaluation

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Classification: Basic Concepts, Decision Trees, and Model Evaluation

Dr. Hui Xiong Rutgers University

Introduction to Data Mining

1/2/2009

General Approach for Building Classification Model


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

Attrib1 Yes No No Yes No No Yes No No No

Attrib2 Large Medium Small Medium Large Medium Large Small Medium Small

Attrib3 125K 100K 70K 120K 95K 60K 220K 85K 75K 90K

Class No No No No Yes No No Yes No Yes

Learn Model

Tid 11 12 13 14 15
10

Attrib1 No Yes Yes No No

Attrib2 Small Medium Large Small Large

Attrib3 55K 80K 110K 95K 67K

Class ? ? ? ? ?

Apply Model

Introduction to Data Mining

1/2/2009

Classification Techniques

Base Classifiers Decision Tree based Methods Rule-based Rule based Methods Nearest-neighbor Neural Networks Nave Bayes and Bayesian Belief Networks Support Vector Machines Ensemble Classifiers Boosting, Bagging, Random Forests
Introduction to Data Mining 1/2/2009 3

Classification: Model Overfitting and Classifier Evaluation


Dr. Hui Xiong Rutgers University

Introduction to Data Mining

1/2/2009

Classification Errors

Training errors (apparent errors) Errors committed on the training set Test errors Errors committed on the test set Generalization errors Expected error of a model over random selection of records from same distribution
Introduction to Data Mining 1/2/2009 5

Example Data Set


Two class problem: +, o 3000 data points (30% for training, 70% for testing) Data set for + class is generated from a uniform distribution Data set for o class is generated from a mixture of 3 gaussian distributions, centered at (5,15), (10,5), and (15,15)

Introduction to Data Mining

1/2/2009

Decision Trees

Decision Tree with 11 leaf nodes

Decision Tree with 24 leaf nodes

Which tree is better?


Introduction to Data Mining 1/2/2009 7

Model Overfitting

Underfitting: when model is too simple, both training and test errors are large Overfitting: when model is too complex, training error is small but test error is large Introduction to Data Mining 1/2/2009 8

Mammal Classification Problem

Training Set Decision Tree Model training error = 0%


Introduction to Data Mining 1/2/2009 9

Effect of Noise
Example: Mammal Classification problem
Model M1: Training Set: train err = 0%, test err = 30%

Test Set:

Model M2: train err = 20%, test err = 10%

Introduction to Data Mining

1/2/2009

10

Lack of Representative Samples


Training Set:

Test Set: Model M3: train err = 0%, test err = 30%

Lack of training records at the leaf nodes for making reliable classification Introduction to Data Mining 1/2/2009 11

Effect of Multiple Comparison Procedure


Consider the task of predicting whether stock market will rise/fall in the next 10 trading days Random guessing: P(correct) = 0.5 Make 10 random guesses in a row:
10 10 10 8 + 9 + 10 = 0.0547 P (# correct 8) = 10 2
Introduction to Data Mining 1/2/2009

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

Up Down Down Up Down Down Up Up Up

Day 10 Down

12

Effect of Multiple Comparison Procedure


Approach: Get 50 analysts Each analyst makes 10 random guesses Choose the analyst that makes the most number of correct predictions Probability y that at least one analyst y makes at least 8 correct predictions
P(# correct 8) = 1 (1 0.0547)50 = 0.9399
Introduction to Data Mining 1/2/2009 13

Effect of Multiple Comparison Procedure


Many algorithms employ the following greedy strategy: Initial model: M Alternative model: M = M , where is a component to be added to the model (e.g., a test condition of a decision tree) Keep M if improvement, (M,M) > Often times, is chosen from a set of alternative p = {1, 2, , k} components, If many alternatives are available, one may inadvertently add irrelevant components to the model, resulting in model overfitting
Introduction to Data Mining 1/2/2009 14

Notes on Overfitting

Overfitting results in decision trees that are more complex than necessary Training error no longer provides a good estimate of how well the tree will perform on previously unseen records Need new ways for estimating generalization errors

Introduction to Data Mining

1/2/2009

15

Estimating Generalization Errors


Resubstitution Estimate Incorporating Model Complexity Estimating Statistical Bounds Use Validation Set

Introduction to Data Mining

1/2/2009

16

Resubstitution Estimate

Using training error as an optimistic estimate of generalization error


e(TL) = 4/24 e(TR) = 6/24

Introduction to Data Mining

1/2/2009

17

Incorporating Model Complexity


Rationale: Occams Razor Given two models of similar generalization errors, one should h ld prefer f th the simpler i l model d l over the more complex model A complex model has a greater chance of being fitted accidentally by errors in data Therefore, one should include model complexity when evaluating a model
Introduction to Data Mining 1/2/2009 18

Pessimistic Estimate

Given a decision tree node t n(t): number of training records classified by t e(t): misclassification error of node t Training error of tree T:

[e(t ) + (t )] e(T ) + (T ) = e' (T ) = N n(t )


i i i i i

: is the cost of adding a node N: total number of training records


Introduction to Data Mining

1/2/2009

19

Pessimistic Estimate

e(T ( L) = 4/24 e(TR) = 6/24 =1

e(TL) = (4 +7 1)/24 = 0.458 e(TR) = (6 + 4 1)/24 = 0.417 Introduction to Data Mining 1/2/2009 20

Minimum Description Length (MDL)


X X1 X2 X3 X4 y 1 0 0 1
A? Yes 0 B1 No B? B2 1 C2 1

C? C1 0

Xn

X X1 X2 X3 X4

y ? ? ? ?

Xn

Cost(Model,Data) = Cost(Data|Model) + Cost(Model) Cost is the number of bits needed for encoding. Search for the least costly model. Cost(Data|Model) encodes the misclassification errors. Cost(Model) uses node encoding (number of children) plus splitting condition encoding.
Introduction to Data Mining 1/2/2009 21

Using Validation Set


Divide training data into two parts: Training set:


use for model building

Validation set:
use for estimating generalization error Note: validation set is not the same as test set

Drawback: Less data available for training

Introduction to Data Mining

1/2/2009

22

Handling Overfitting in Decision Tree


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). Stop if estimated generalization error falls below certain threshold
1/2/2009 23

Introduction to Data Mining

Handling Overfitting in Decision Tree


Post-pruning Grow decision tree to its entirety Subtree replacement


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

Subtree raising

Replace subtree with most frequently used branch


1/2/2009 24

Introduction to Data Mining

Example of Post-Pruning
Training Error (Before splitting) = 10/30 Class = Yes Class = No 20 10 Pessimistic error = (10 + 0.5)/30 = 10.5/30 Training Error (After splitting) = 9/30 Pessimistic error (After splitting) = (9 + 4 0.5)/30 = 11/30

Error = 10/30

A?
A1 A2
Class = Yes Class = No 8 4 Class = Yes Class = No 3 4

PRUNE!

A4 A3
Class = Yes Class = No 4 1 Class = Yes Class = No 5 1

Introduction to Data Mining

1/2/2009

25

Examples of Post-pruning

Introduction to Data Mining

1/2/2009

26

Evaluating Performance of Classifier


Model Selection Performed during model building Purpose is to ensure that model is not overly complex (to avoid overfitting) Need to estimate generalization error Model Evaluation Performed after model has been constructed Purpose is to estimate performance of classifier on previously unseen data (e.g., test set)
Introduction to Data Mining 1/2/2009 27

Methods for Classifier Evaluation


Holdout Reserve k% for training and (100-k)% for testing Random subsampling p g Repeated holdout 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 Bootstrap Sampling with replacement 1 b .632 bootstrap:
accboot = b

(0.632 acc + 0.368 acc )


i =1 i s

Introduction to Data Mining

1/2/2009

28

Methods for Comparing Classifiers


Given

two models:

Model M1: accuracy = 85%, tested on 30 instances Model M2: accuracy = 75%, tested on 5000 instances 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?

Introduction to Data Mining

1/2/2009

29

Confidence Interval for Accuracy


Prediction can be regarded as a Bernoulli trial A Bernoulli trial has 2 possible outcomes

Coin toss head/tail Prediction correct/wrong x Bin(N, p) x: number of correct predictions

Collection of Bernoulli trials has a Binomial distribution:


Estimate number of events Given Gi N and d p, fi find d P( P(x=k) k) or E( E(x) ) Example: Toss a fair coin 50 times, how many heads would turn up? Expected number of heads = Np = 50 0.5 = 25
Introduction to Data Mining 1/2/2009 30

Confidence Interval for Accuracy


Estimate parameter of distribution Given x (# of correct predictions) or equivalently, acc=x/N, and N (# of test instances), instances) Find upper and lower bounds of p (true accuracy of model)

Introduction to Data Mining

1/2/2009

31

Confidence Interval for Accuracy


For large test sets (N > 30),


acc has a normal distribution with mean p and variance p(1-p)/N

Area = 1 -

P( Z <
/2

acc p <Z p (1 p ) / N

1 / 2

)
Z/2 Z1- /2
2

= 1

C fid Confidence I Interval t lf for p:

2 N acc + Z Z + 4 N acc 4 N acc p= 2( N + Z )


2 2

/2

/2

/2

Introduction to Data Mining

1/2/2009

32

Confidence Interval for Accuracy


Consider a model that produces an accuracy of 80% when evaluated on 100 test instances:
N=100 N=100, acc = 0 0.8 8 Let 1- = 0.95 (95% confidence) From probability table, Z/2=1.96
N 50 0.670 0.888 100 0.711 0.866 500 0.763 0.833 1000 0.774 0.824 5000 0.789 0.811

1-

0.99 2.58 0.98 2.33 0.95 1.96 0 90 1.65 0.90 1 65

p(lower) p(upper)

Introduction to Data Mining

1/2/2009

33

Comparing Performance of 2 Models


Given

two models, say M1 and M2, which is better?


M1 is tested on D1 (size=n1), found error rate = e1 M2 is tested on D2 (size=n2), found error rate = e2 Assume D1 and D2 are independent If n1 and n2 are sufficiently large, then

e1 ~ N (1 , 1 )
Approximate:

e2 ~ N (2 , 2 )
=
i

e (1 e ) n
i i i

Introduction to Data Mining

1/2/2009

34

Comparing Performance of 2 Models


To test if performance difference is statistically significant: d = e1 e2


d ~ N(dt,t) where dt is the true difference Since D1 and D2 are independent, their variance adds up:

= + +
2 2 2 2 t 1 2 1

2 2

e1(1 e1) e2(1 e2) + n1 n2


d =d Z
t

At (1-) confidence level,


Introduction to Data Mining

/2

1/2/2009

35

An Illustrative Example
Given: M1: n1 = 30, e1 = 0.15 M2: n2 = 5000, e2 = 0.25 d = |e2 e1| = 0.1 0 1 (2-sided (2 sided test)

=
d

0.15(1 0.15) 0.25(1 0.25) + = 0.0043 30 5000

At 95% confidence level, Z/2=1.96

d = 0.100 1.96 0.0043 = 0.100 0.128


t

=> Interval contains 0 => difference may not be statistically significant


Introduction to Data Mining 1/2/2009 36

Support Vector Machines (SVMs)


SVMs are a rare example of a methodology where geometric intuition, elegant mathematics, theoretical guarantees, and practical use meet.

Find a linear hyperplane (decision boundary) that separates the data


Introduction to Data Mining 1/2/2009 37

Support Vector Machines

One Possible Solution


Introduction to Data Mining 1/2/2009 38

Support Vector Machines

Another possible solution


Introduction to Data Mining 1/2/2009 39

Support Vector Machines

Other possible solutions


Introduction to Data Mining 1/2/2009 40

Support Vector Machines

Which one is better? B1 or B2? How do you define better?


Introduction to Data Mining 1/2/2009 41

Support Vector Machines

Find hyperplane maximizes the margin => B1 is better than B2


Introduction to Data Mining 1/2/2009 42

Support Vector Machines

r r w x + b = 0 r r w x + b = 1 r r w x + b = +1

1 r f (x) = 1

r r if w x + b 1 r r if w x + b 1

2 Margin = r 2 || w ||
1/2/2009 43

Introduction to Data Mining

Support Vector Machines


2 We want to maximize: Margin = r 2 || w ||

r || w ||2 L( w) = Which Whi h i is equivalent i l tt to minimizing: i i i i 2 But subjected to the following constraints: r r if w x i + b 1 1 r f ( xi ) = r r 1 if w x i + b 1

This is a constrained optimization p p problem Numerical approaches to solve it (e.g., quadratic programming)

Introduction to Data Mining

1/2/2009

44

Support Vector Machines


What if the problem is not linearly separable?

Introduction to Data Mining

1/2/2009

45

Support Vector Machines


What if the problem is not linearly separable? Introduce slack variables


Need to minimize: Subject to:

r || w ||2 N k L(w) = + C i 2 i=1

1 r f ( xi ) = 1

r r if w x i + b 1 - i r r if w x i + b 1 + i

Introduction to Data Mining

1/2/2009

46

NonlinearSupportVectorMachines

What if decision boundary is not linear?


x2 X X x12 X OO O O x1

X X O O O O X X x1

Introduction to Data Mining

1/2/2009

47

Mapping into a New Feature Space


: x X = (x) (x1,x2) = (x1,x2,x12,x22,x1x2) than run SVM on xi, run it on (xi) Find non-linear separator in input space What if (xi) is really big? Use kernels!
Rather
Introduction to Data Mining 1/2/2009 48

Examples of Kernel Functions


Polynomial kernel with degree d

Radial basis function kernel with width

Sigmoid with parameter and It does not satisfy the Mercer condition on all and
Introduction to Data Mining 1/2/2009 49

Characteristics of SVMs

Perform best on the average or outperform other techniques across many important applications The results are stable, reproducible, and largely independent of the specific optimization algorithm A convex optimization problem
Lead to the global optimum

The parameter selection problem


The type of kernels (including its parameters) The Th attributes tt ib t to t be b included. i l d d

The results are hard to interpret Computational challenge


Typically quadratic and multi-scan of the data
Introduction to Data Mining 1/2/2009 50

You might also like