Data Mining: Classification Methods Overview
Data Mining: Classification Methods Overview
University
SoEEC:CS
Data Mining
Classification
Chapter 4
1
1
Lecture Outlines
• Classification Methods
1. General Introduction
2. Decision Trees
3. Rule based classifiers
4. Bayesian Classification
2
General Introduction
• Classification Definition
• Supervised vs Unsupervised
• Typical Applications
• Classification Tasks
• Data Preparation
• Performance Evaluation
3
General Introduction
• Given a collection of records (training set )
– Each record contains a set of attributes, one of the attributes is the class.
• Find a model for class attribute as a function of the values of other attributes.
• Definition: Given a database D={t1,t2,..,tn} and a set of classes C= {c1, c2, …, cm},
Classification problems is to define a mapping f : D→C, where each ti is
assigned to one class. That is, Classification is the task of learning a target
function f (-also known as classification model ) that maps each attribute set ti
to one of the predefined class ci .
4
Classification vs. Prediction
• Classification
– predicts categorical class labels (discrete or nominal)
– classifies data (constructs a model) based on the training set and
the values (class labels) in a classifying attribute and uses it in
classifying new data
• Descriptive Modeling: A classification model
can serve as an explanatory tool to distinguish
between objects of different classes. e.g.
vertebrate data set.
• Prediction
– models continuous-valued functions, i.e., predicts unknown or
missing values
• Predictive Modeling: A classification model can
also be used to predict the class label of
unknown records.
5
PART 1: General Introduction
6
General Introduction
7
General Introduction
9
PART 1: General Introduction- Classification Task
Model Construction:
Classification
Algorithms
Training
Data
12
General Introduction- Classification Task
Classifier
Testing
Data Unseen Data
Figure : The data classification process: (a) Learning : Training data are analyzed by a
classification algorithm. Her the class label attribute is credit_rating, and the learned model or
classifier is represented in the form of classification rules.
14
General Introduction- Classification Task
b) Classification: Test data are used to estimate the accuracy of the classification rules. If
the accuracy is considered acceptable, the rules can be applied to the classification of new
data tuples.
15
General Introduction- Classification Task
Another Illustration of Classification Model:
Training Set
Apply
Tid Attrib1 Attrib2 Attrib3 Class Model
11 No Small 55K ?
12 Yes Medium 80K ?
13 Yes Large 110K ? Deduction
14 No Small 95K ?
15 No Large 67K ?
10
Test Set
16
General Introduction - Data Preparation
• Data cleaning
– Preprocess data in order to reduce noise and handle
missing values
• Data transformation
– Generalize and/or normalize data
17
General Introduction - Performance Evaluation
Predicted Class
18
General Introduction- Performance Evaluation
• Accuracy
– classifier accuracy: predicting class label
– predictor accuracy: guessing value of predicted attributes
• Speed
– time to construct the model (training time)
– time to use the model (classification/prediction time)
• Interpretability
– understanding and insight provided by the model
• Other measures, e.g., goodness of rules, such as decision tree size or
compactness of classification rules.
19
Part 2: Decision Trees
• What is a Decision Tree?
• Decision Tree Induction Algorithms
• Building of a Decision Tree
• Choosing Splitting Attribute
• Evaluation of DT
– Information Gain
– Gini Index
– Gain Ratio
– Misclassification Error
• Overfitting & Underfitting
• Pruning
20
What is a Decision Tree?
A decision tree is a flow-chart-like tree structure, where each
internal node denotes a test on an attribute, each branch
represents an outcome of the test, and leaf nodes
represent classes or class distribution.
– Each arc (or edge) is labeled with a predicate that can be applied to the attribute
associated with the parent
23
What is a Decision Tree?
Body
Root node
Temperature
Gives Non-
Internal
Birth Mammals
node
Mammals Non-
Mammals Figure :
A decision tree for the
Mammal classification
problem
Leaf Nodes
24
What is a Decision Tree?
Name Body Gives Birth ….. Class
Unlabeled data temperature
Flamingo Warm NO …. ?
Body
Temperature
Warm Cold
Gives Non-
Birth Mammals
No
Yes
Non-
Mammals Mammals
Figure : Classifying an unlabeled vertebrate. The dashed lines represent the outcomes of applying various attribute test conditions on the
unlabeled vertebrate. The vertebrate is eventually assigned to the Non-mammal class.
25
Decision Tree- An Example
Tid Attrib1 Attrib2 Attrib3 Class
Tree
1 Yes Large 125K No Induction
2 No Medium 100K No algorithm
3 No Small 70K No
6 No Medium 60K No
Training Set
Apply
Model Decision
Tid Attrib1 Attrib2 Attrib3 Class
?
Tree
11 No Small 55K
12 Yes Medium 80K ?
15 No Large 67K ?
10
Test Set
26
Decision Tree –An Example(contd..)
l l us
ri ca ri ca uo
o o in
teg teg n t a ss
c a c a co c l
Tid Refund Marital Taxable
Splitting Attributes
Status Income Cheat
28
Decision Tree –An Example (contd..)
Tid Attrib1 Attrib2 Attrib3 Class
Tree
1 Yes Large 125K No Induction
2 No Medium 100K No algorithm
3 No Small 70K No
6 No Medium 60K No
Training Set
Apply
Model Decision
Tid Attrib1 Attrib2 Attrib3 Class
Tree
11 No Small 55K ?
15 No Large 67K ?
10
Test Set
29
Decision Tree –An Example (contd..)
Apply Model to Test Data
Test Data
Start from the root of tree. Refund Marital Taxable
Status Income Cheat
No Married 80K ?
Refund 10
Yes No
NO MarSt
Single, Divorced Married
TaxInc NO
< 80K > 80K
NO YES
30
Decision Tree –An Example (contd..)
Apply Model to Test Data Test Data
Refund Marital Taxable
Status Income Cheat
No Married 80K ?
Refund 10
Yes No
NO MarSt
Single, Divorced Married
TaxInc NO
< 80K > 80K
NO YES
31
Decision Tree –An Example (contd..)
Apply Model to Test Data Test Data
Refund Marital Taxable
Status Income Cheat
No Married 80K ?
Refund 10
Yes No
NO MarSt
Single, Divorced Married
TaxInc NO
< 80K > 80K
NO YES
32
Decision Tree –An Example (contd..)
Apply Model to Test Data Test Data
Refund Marital Taxable
Status Income Cheat
No Married 80K ?
Refund 10
Yes No
NO MarSt
Single, Divorced Married
TaxInc NO
< 80K > 80K
NO YES
33
Decision Tree –An Example (contd..)
Apply Model to Test Data Test Data
Refund Marital Taxable
Status Income Cheat
No Married 80K ?
Refund 10
Yes No
NO MarSt
Single, Divorced Married
TaxInc NO
< 80K > 80K
NO YES
34
Decision Tree –An Example (contd..)
Test Data
Apply Model to Test Data Refund Marital Taxable
Status Income Cheat
No Married 80K ?
Refund 10
Yes No
NO MarSt
Single, Divorced Married Assign Cheat to
“No”
TaxInc NO
< 80K > 80K
NO YES
35
Decision Tree -Another Illustration
Table-4: Training dataset for ‘buys_computer’ example
36
Decision Tree -Another Illustration
Output: A Decision Tree for “buys_computer”
age?
<=30 overcast
31..40 >40
no yes no yes
37
Decision Tree -Another Illustration
38
Decision Tree Induction
• Many Algorithms:
– Hunt’s Algorithm (one of the earliest)
39
Algorithm for Decision Tree Induction
41
Choosing the Splitting Attribute
• At each node, available attributes are evaluated on the basis of
separating the classes of the training examples. An evaluation
(goodness) function is used for this purpose.
42
Computing information
• Information is measured in bits
– Given a probability distribution, the info required to predict an
event is the distribution’s entropy
– Entropy gives the information required in bits (this can involve
fractions of bits!)
• Formula for computing the entropy:
entropy( p1 , p2 , , pn ) p1logp1 p2 logp2 pn logpn
43
Attribute Selection Measure:
Information Gain (ID3/C4.5)
Select the attribute with the highest information
gain
Let pi be the probability that an arbitrary tuple in D
belongs to class Ci, estimated by |Ci, D|/|D|
m
Expected information (entropy) needed
Info( D ) to (classify
pi log 2 pi )
a tuple in D: i 1
46
Rule Extraction from a Decision Tree age?
Rules are easier to understand than large trees
<=30 31..40
One rule is created for each path from the root >40
Name Blood Type Give Birth Can Fly Live in Water Class
hawk warm no yes no ?
grizzly bear warm yes no no ?
P( H | X) P(X | H ) P( H )
P(X)
Towards Naïve Bayesian Classifiers
• Let D be a training set of tuples and their associated class labels,
and each tuple is represented by an n-D attribute vector X = (x1, x2,
…, xn)
• Suppose there are m classes C1, C2, …, Cm.
• Classification is to derive the maximum posteriori, i.e., the
maximal P(Ci|X)
• This can be derived from Bayes’ theorem
P(X | C )P(C )
P(C | X) i i
i P(X)
• Since P(X) is constant for all classes, only
Outlook P N Humidity P N
sunny 2/9 3/5 high 3/9 4/5
overcast 4/9 0 normal 6/9 1/5
rain 3/9 2/5
Tempreature Windy
hot 2/9 2/5 true 3/9 3/5
mild 4/9 2/5 false 6/9 2/5
cool 3/9 1/5
• We also have the probabilities
– P = 9/14
– N = 5/14
Naive Bayesian Classifier Example
• To classify a new sample X:
– outlook = sunny
– temperature = cool
– humidity = high
– windy = false
• Prob(P|X) = Prob(P)*Prob(sunny|P)*Prob(cool|P)*
Prob(high|P)*Prob(false|P) = 9/14*2/9*3/9*3/9*6/9 = 0.01
• Prob(N|X) = Prob(N)*Prob(sunny|N)*Prob(cool|N)*
Prob(high|N)*Prob(false|N) = 5/14*3/5*1/5*4/5*2/5 =
0.013
• Therefore X takes class label N
Naive Bayesian Classifier Example
• Second example X = <rain, hot, high, false>
• P(X|p)·P(p) =
P(rain|p)·P(hot|p)·P(high|p)·P(false|p)·P(p) =
3/9·2/9·3/9·6/9·9/14 = 0.010582
• P(X|n)·P(n) =
P(rain|n)·P(hot|n)·P(high|n)·P(false|n)·P(n) =
2/5·2/5·4/5·2/5·5/14 = 0.018286
63