Data Mining
Classification: Basic Concepts, Decision
Trees, and Model Evaluation
Lecture Notes for Chapter 4
Introduction to Data Mining
by
Tan, Steinbach, Kumar
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 1
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 2
Classification: Definition
OGiven a collection of records (training set )
Each record contains a set of attributes, one of the
attributes is the class.
OFind a model for class attribute as a function
of the values of other attributes.
OGoal: 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.
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 3
Illustrating Classification Task
Apply
Model
Induction
Deduction
Learn
Model
Model
Tid Attrib1 Attrib2 Attrib3 Class
1 Yes Large 125K No
2 No Medium 100K No
3 No Small 70K No
4 Yes Medium 120K No
5 No Large 95K Yes
6 No Medium 60K No
7 Yes Large 220K No
8 No Small 85K Yes
9 No Medium 75K No
10 No Small 90K Yes
10
Tid Attrib1 Attrib2 Attrib3 Class
11 No Small 55K ?
12 Yes Medium 80K ?
13 Yes Large 110K ?
14 No Small 95K ?
15 No Large 67K ?
10
Test Set
Learning
algorithm
Training Set
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 4
Examples of Classification Task
OPredicting tumor cells as benign or malignant
OClassifying credit card transactions
as legitimate or fraudulent
OClassifying secondary structures of protein
as alpha-helix, beta-sheet, or random
coil
OCategorizing news stories as finance,
weather, entertainment, sports, etc
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 5
Classification Techniques
ODecision Tree based Methods
ORule-based Methods
OMemory based reasoning
ONeural Networks
ONaïve Bayes and Bayesian Belief Networks
OSupport Vector Machines
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 6
Example of a Decision Tree
Tid Refund Marital
Status
Taxable
Income Cheat
1Yes Single 125K No
2No Married 100K No
3No Single 70K No
4Yes Married 120K No
5No Divorced 95K Yes
6No Married 60K No
7Yes Divorced 220K No
8No Single 85K Yes
9No Married 75K No
10 No Single 90K Yes
10
categorical
categorical
continuous
class
Refund
MarSt
TaxInc
YES
NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Splitting Attributes
Training Data Model: Decision Tree
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 7
Another Example of Decision Tree
Tid Refund Marital
Status
Taxable
Income Cheat
1Yes Single 125K No
2No Married 100K No
3No Single 70K No
4Yes Married 120K No
5No Divorced 95K Yes
6No Married 60K No
7Yes Divorced 220K No
8No Single 85K Yes
9No Married 75K No
10 No Single 90K Yes
10
categorical
categorical
continuous
class
MarSt
Refund
TaxInc
YES
NO
NO
NO
Yes No
Married
Single,
Divorced
< 80K > 80K
There could be more than one tree that
fits the same data!
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 8
Decision Tree Classification Task
Apply
Model
Induction
Deduction
Learn
Model
Model
Tid Attrib1 Attrib2 Attrib3 Class
1 Yes Large 125K No
2 No Medium 100K No
3 No Small 70K No
4 Yes Medium 120K No
5 No Large 95K Yes
6 No Medium 60K No
7 Yes Large 220K No
8 No Small 85K Yes
9 No Medium 75K No
10 No Small 90K Yes
10
Tid Attrib1 Attrib2 Attrib3 Class
11 No Small 55K ?
12 Yes Medium 80K ?
13 Yes Large 110K ?
14 No Small 95K ?
15 No Large 67K ?
10
Test Set
Tree
Induction
algorithm
Training Set
Decision
Tree
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 9
Apply Model to Test Data
Refund
MarSt
TaxInc
YES
NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Refund Marital
Status
Taxable
Income Cheat
No Married 80K ?
10
Test Data
Start from the root of tree.
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 10
Apply Model to Test Data
Refund
MarSt
TaxInc
YES
NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Refund Marital
Status
Taxable
Income Cheat
No Married 80K ?
10
Test Data
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 11
Apply Model to Test Data
Refund
MarSt
TaxInc
YES
NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Refund Marital
Status
Taxable
Income Cheat
No Married 80K ?
10
Test Data
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 12
Apply Model to Test Data
Refund
MarSt
TaxInc
YES
NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Refund Marital
Status
Taxable
Income Cheat
No Married 80K ?
10
Test Data
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 13
Apply Model to Test Data
Refund
MarSt
TaxInc
YES
NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Refund Marital
Status
Taxable
Income Cheat
No Married 80K ?
10
Test Data
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 14
Apply Model to Test Data
Refund
MarSt
TaxInc
YES
NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Refund Marital
Status
Taxable
Income Cheat
No Married 80K ?
10
Test Data
Assign Cheat to “No”
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 15
Decision Tree Classification Task
Apply
Model
Induction
Deduction
Learn
Model
Model
Tid Attrib1 Attrib2 Attrib3 Class
1 Yes Large 125K No
2 No Medium 100K No
3 No Small 70K No
4 Yes Medium 120K No
5 No Large 95K Yes
6 No Medium 60K No
7 Yes Large 220K No
8 No Small 85K Yes
9 No Medium 75K No
10 No Small 90K Yes
10
Tid Attrib1 Attrib2 Attrib3 Class
11 No Small 55K ?
12 Yes Medium 80K ?
13 Yes Large 110K ?
14 No Small 95K ?
15 No Large 67K ?
10
Test Set
Tree
Induction
algorithm
Training Set
Decision
Tree
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 16
Decision Tree Induction
OMany Algorithms:
Hunt’s Algorithm (one of the earliest)
CART
ID3, C4.5
SLIQ,SPRINT
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 17
General Structure of Hunt’s Algorithm
OLet Dtbe the set of training records
that reach a node t
OGeneral Procedure:
If Dtcontains records that
belong the same class yt, then t
is a leaf node labeled as yt
If Dtis an empty set, then t is a
leaf node labeled by the default
class, yd
If Dtcontains 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.
Tid Refund Marital
Status
Taxable
Income Cheat
1 Yes Single 125K No
2 No Married 100K No
3 No Single 70K No
4 Yes Married 120K No
5 No Divorced 95K Yes
6 No Married 60K No
7 Yes Divorced 220K No
8 No Single 85K Yes
9 No Married 75K No
10 No Single 90K Yes
10
Dt
?
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 18
Hunt’s Algorithm
Don’t
Cheat
Refund
Don’t
Cheat
Don’t
Cheat
Yes No
Refund
Don’t
Cheat
Yes No
Marital
Status
Don’t
Cheat
Cheat
Single,
Divorced Married
Taxable
Income
Don’t
Cheat
< 80K >= 80K
Refund
Don’t
Cheat
Yes No
Marital
Status
Don’t
Cheat
Cheat
Single,
Divorced Married
Tid Refund Marital
Status
Taxable
Income Cheat
1Yes Single 125K No
2No Married 100K No
3No Single 70K No
4Yes Married 120K No
5No Divorced 95K Yes
6No Married 60K No
7Yes Divorced 220K No
8No Single 85K Yes
9No Married 75K No
10 No Single 90K Yes
10
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 19
Tree Induction
OGreedy strategy.
Split the records based on an attribute test
that optimizes certain criterion.
OIssues
Determine how to split the records
How to specify the attribute test condition?
How to determine the best split?
Determine when to stop splitting
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 20
Tree Induction
OGreedy strategy.
Split the records based on an attribute test
that optimizes certain criterion.
OIssues
Determine how to split the records
How to specify the attribute test condition?
How to determine the best split?
Determine when to stop splitting
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 21
How to Specify Test Condition?
ODepends on attribute types
Nominal
Ordinal
Continuous
ODepends on number of ways to split
2-way split
Multi-way split
© Tan,Steinbach, Kumar Introduction to Data Mining 4/18/2004 22
Splitting Based on Nominal Attributes
OMulti-way split: Use as many partitions as distinct
values.
OBinary split: Divides values into two subsets.
Need to find optimal partitioning.
CarType
Family
Sports
Luxury
CarType
{Family,
Luxury} {Sports}
CarType
{Sports,
Luxury} {Family} OR
OMulti-way split: Use as many partitions as distinct
values.
OBinary split: Divides values into two subsets.
Need to find optimal partitioning.
OWhat about this split?
Splitting Based on Ordinal Attributes
Size
Small
Medium
Large
Size
{Medium,
Large} {Small}
Size
{Small,
Medium} {Large} OR
Size
{Small,