CSC479
Data Mining
Lecture # 11
Classification
Basic Concepts
Decision Trees
(Ch # 8: Data Mining-Concepts and
Catching tax-evasion
Tax-return data for year 2011
A new tax return for 2012 Is this a cheating tax return?
An instance of the classification problem: learn a method for discriminating between records of different classes (cheaters vs non-cheaters)
2
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
Refund Marital Status
Taxable
Income Cheat
No Married 80K ?
What is classification?
Classification is the task of learning a target function f that
maps attribute set x to one of the predefined class labels y
cate goric al cate goric al cont inuo us class
One of the attributes is the class attribute
In this case: Cheat
Two class labels (or classes): Yes (1), No (0)
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
What is classification (cont…)
The target function
f
is known as a
classification model
Descriptive modeling:
Explanatory tool
to
distinguish between objects of different
classes (e.g., understand why people
cheat on their taxes)
Predictive modeling:
Predict a class of a
Examples of Classification Tasks
Predicting tumor cells as benign or malignant
Classifying credit card transactions as legitimate or fraudulent
Categorizing news stories as finance, weather, entertainment, sports, etc
Identifying spam email, spam web pages, adult content
Understanding if a web query has commercial intent or
General approach to classification
Training set consists of records with known class
labels
Training set is used to build a classification model
A labeled test set of previously unseen data records
is used to evaluate the quality of the model.
The classification model is applied to new records with unknown class labels
Illustrating Classification Task
Apply Model Induction Deduction Learn Model ModelTid 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
Learning algorithm
Evaluation of classification models
Counts of
test records
that are correctly
(or incorrectly) predicted by the
classification model
Confusion matrix
Class = 1 Class = 0Class = 1 f11 f10
Class = 0 f01 f00
Classification Techniques
Decision Tree based Methods
Rule-based Methods
Memory based reasoning
Neural Networks
Naïve Bayes and Bayesian Belief Networks
Classification Techniques
Decision Tree based Methods
Rule-based Methods
Memory based reasoning
Neural Networks
Naïve Bayes and Bayesian Belief Networks
Support Vector Machines
Decision Trees
Decision tree
A flow-chart-like tree structure
Internal node denotes a test on an attribute
Branch represents an outcome of the test
Leaf nodes represent class labels or class
Example of a Decision Tree
cate goric al cate goric al cont inuo us class Refund MarSt TaxInc YES NO NO NO Yes No Married Single, Divorced< 80K > 80K
Splitting Attributes
Training Data Model: Decision Tree
Test outcome
Class labels
12
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
Another Example of Decision Tree
cate goric al cate goric al cont inuo usclass MarSt
Refund TaxInc YES NO NO NO Yes No
Married DivorcedSingle,
< 80K > 80K
There could be more than one tree that fits the same data!
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
Decision Tree Classification Task
Decision Tree 14 Apply Model Induction Deduction Learn Model ModelTid 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 ?
Apply Model to Test Data
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Test Data
Start from the root of tree. Refund Marital
Status
Taxable
Income Cheat
No Married 80K ?
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Test Data
Apply Model to Test Data
16
Refund Marital Status
Taxable
Income Cheat
No Married 80K ?
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Test Data
Apply Model to Test Data
Refund Marital Status
Taxable
Income Cheat
No Married 80K ?
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married Single, Divorced
< 80K > 80K
Test Data
Apply Model to Test Data
18
Refund Marital Status
Taxable
Income Cheat
No Married 80K ?
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Test Data
Apply Model to Test Data
Refund Marital Status
Taxable
Income Cheat
No Married 80K ?
Refund
MarSt
TaxInc
YES NO
NO
NO
Yes No
Married
Single, Divorced
< 80K > 80K
Test Data
Assign Cheat to “No”
Apply Model to Test Data
20
Refund Marital Status
Taxable
Income Cheat
No Married 80K ?
Decision Tree Classification Task
Decision Tree Apply Model Induction Deduction Learn Model ModelTid 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 ?
Tree Induction algorithm
Tree Induction
Finding the best decision tree is NP-hard
Greedy strategy.
Split the records based on an attribute test that optimizes
certain criterion.
Many Algorithms:
Hunt’s Algorithm (one of the earliest) CART
ID3, C4.5
SLIQ, SPRINT
The central choice in the ID3 algorithm is selecting which attribute to test at each node in the tree
We would like to select the attribute which is most useful for classifying examples
For this we need a good quantitative measure
For this purpose a statistical property, called
information gain is used
- In order to define information gain precisely, we
begin by defining entropy
- Entropy is a measure commonly used in
information theory.
- Entropy characterizes the impurity of an
arbitrary collection of examples
Which Attribute is the Best Classifier?
Definition of Entropy
Entropy (D)
Entropy of data set D is denoted by H(D)
Cis are the possible classes
pi = fraction of records from D that have class C
Entropy
2
( )
log
i
i i
c
Entropy Examples
Example:
10 records have class A
20 records have class B
30 records have class C
40 records have class D
Entropy = -[(.1 log .1) + (.2 log .2) + (.3
log .3) + (.4 log .4)]
Entropy = 1.846
Splitting Criterion
Example:
Two classes,
+/-
100 records overall (50 +s and 50 -s)
A and B are two binary attributes
• Records with A=0: 48+,
2-Records with A=1: 2+,
48-• Records with B=0: 26+,
24-Records with B=1: 24+,
26-
Splitting on A is better than splitting on B
• A does a good job of separating +s and -s
The expected information needed to classify a tuple in D is
= Entropy
How much more information would we still need
(after partitioning at attribute A) to arrive at an exact classification? This amount is measured by
= H(D, A)
Info Gain (D, A) = H(D) – H(D, A)
In general, we write Gain (D, A), where D is the collection of examples & A is an attribute
Which Attribute is the Best Classifier?
Information Gain
Information Gain
Gain of an attribute split: compare the
impurity of the parent node with the average impurity of the child nodes
Maximizing the gain Minimizing the weighted
average impurity measure of children nodes
1
(
)
v j(
j)
j
D
InfoGain
H parent
H D
D
30
Examples Constructing Decision Tree
So the attribute Age will be placed at root
level.
For placement at second level we find
32