Classification Algorithms Overview
Classification Algorithms Overview
1
Concept of Classification
2
Concept of Classification
Training data
3
Classification—A Two-Step Process
Model construction: describing a set of predetermined classes
Each tuple/sample is assumed to belong to a predefined class, as
mathematical formulae
Model usage: for classifying future or unknown objects
Estimate accuracy of the model
The known label of test sample is compared with the classified result
from the model
Accuracy rate is the percentage of test set samples that are correctly
classified by the model
Test set is independent of training set (otherwise overfitting)
If the accuracy is acceptable, use the model to classify new data
Note: If the test set is used to select models, it is called validation (test) set
4
Process (1): Model Construction
Classification
Algorithms
Training
Data
Classifier
Testing
Data Unseen Data
(Jeff, Professor, 4)
NAME RANK YEARS TENURED
Tom Assistant Prof 2 no Tenured?
Merlisa Associate Prof 7 no
George Professor 5 yes
Joseph Assistant Prof 7 yes
6
Classification type
Decision Tree classifier
Rule Based Classifier
Nearest Neighbor Classifier
Bayesian Classifier
Artificial Neural Network (ANN) Classifier
Others
7
Decision Tree classifier
A decision tree is tree in which each branch node represents a
choice between a number of alternatives and each leaf node
represents a classification or decision.
Decision tree is a classifier in the form of a tree structure where
a leaf node indicates the class of instances, a decision node
specifies some test to be carried out on a single attribute value
with one branch and sub-tree for each possible outcome of the
test.
A decision tree can be used to classify an instance by starting at
root of the tree and moving through it until leaf node. The leaf
node provides the corresponding class of instance.
8
Decision Tree Induction: An Example
age income student credit_rating buys_computer
<=30 high no fair no
Training data set: Buys_computer <=30 high no excellent no
The data set follows an example of 31…40 high no fair yes
>40 medium no fair yes
Quinlan’s ID3 (Playing Tennis) >40 low yes fair yes
Resulting tree: >40 low yes excellent no
31…40 low yes excellent yes
age? <=30 medium no fair no
<=30 low yes fair yes
>40 medium yes fair yes
<=30 medium yes excellent yes
<=30 overcast
31..40 >40 31…40 medium no excellent yes
31…40 high yes fair yes
>40 medium no excellent no
no yes no yes
9
Decision Tree Algorithm
Hunt’s Algorithm
10
Hunt’s Algorithm
Hunt's algorithm grows a decision tree in a recursive fashion by partitioning the
training data into successively into subsets.
Let Dt be the set of training data that reach a node ‘t’. The general recursive
procedure is defined as:
If Dt contains records that belong the same class y t, then t is a leaf node labeled as
yt.
If Dt is an empty set, then t is a leaf node labeled by the default class, y d
If Dt contains records that belong to more than one class, use an attribute test to
split the data into smaller subsets.
It recursively applies the procedure to each subset until all the records in the subset
belong to the same class.
The Hunt's algorithm assumes that each combination of attribute sets has a unique
class label during the procedure.
If all the records associated with Dt have identical attribute values except for the class
label, then it is not possible to split these records any future. In this case, the node is
declared a leaf node with the same class label as the majority class of training records
associated with this node.
11
Example
12
Tree Induction:
Tree induction is based on Greedy Strategy i.e. split the records based
on an attribute test that optimize certain criterion.
Issues:
How to split the record?
How to specify the attribute test condition?
Depends on attribute types and number of ways to split the record i.e. 2-
ways split /multi-way split.
Depends upon attribute types. (Nominal, Ordinal, Continuous)
When to stop splitting?
When all records are belongs to the same class or all records have similar
attributes.
How to determine the best split?
Nodes with homogenous class distribution are preferred.
Measure the node impurity.
Gini-Index
Entropy
Misclassification Error
13
Entropy
Entropy quantifies the amount of impurity or
randomness in a dataset.
14
Entropy
15
Information Gain
Information Gain (IG) tells you how much entropy is
reduced after splitting the data on a given attribute.
16
Algorithm for Decision Tree Induction
Basic algorithm (a greedy algorithm)
Tree is constructed in a top-down recursive divide-and-conquer
manner
At start, all the training examples are at the root
discretized in advance)
Examples are partitioned recursively based on selected
attributes
Test attributes are selected on the basis of a heuristic or
19
Example ID3
20
21
Gini Index (CART, IBM IntelligentMiner)
If a data set D contains examples from n classes, gini index,
gini(D) is defined as n 2
gini( D) 1 p j
j 1
where pj is the relative frequency of class j in D
If a data set D is split on A into two subsets D1 and D2, the gini
index gini(D) is defined as |D | |D |
gini A ( D) 1 gini( D1) 2 gini( D 2)
|D| |D|
Reduction in Impurity:
gini( A) gini( D) giniA ( D)
The attribute provides the smallest ginisplit(D) (or the largest
reduction in impurity) is chosen to split the node (need to
enumerate all the possible splitting points for each attribute)
22
Construct Decision tree using
Gini Index
23
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|
Expected information (entropy) needed to classify
m a tuple in D:
Info( D) pi log 2 ( pi )
i 1
Information needed (after using A to split D into v partitions) to
v | D |
classify D:
Info A ( D )
j
Info( D j )
j 1 | D |
27
Gain Ratio for Attribute Selection (C4.5)
Information gain measure is biased towards attributes with a
large number of values
C4.5 (a successor of ID3) uses gain ratio to overcome the
problem (normalization to information gain)
v | Dj | | Dj |
SplitInfo A ( D) log 2 ( )
j 1 |D| |D|
GainRatio(A) = Gain(A)/SplitInfo(A)
Ex.
or outliers
Poor accuracy for unseen samples
34
35
Chapter 3. Classification: Basic Concepts
36
Using IF-THEN Rules for Classification
37
Rule Extraction from a Decision Tree
Rules are easier to understand than large
trees age?
One rule is created for each path from the <=30 31..40 >40
root to a leaf student? credit rating?
yes
Each attribute-value pair along a path forms a
no yes excellent fair
conjunction: the leaf holds the class
no yes no yes
prediction
Rules are mutually exclusive and exhaustive
Example: Rule extraction from our buys_computer decision-tree
IF age = young AND student = no THEN buys_computer = no
IF age = young AND student = yes THEN buys_computer = yes
IF age = mid-age THEN buys_computer = yes
IF age = old AND credit_rating = excellent THEN buys_computer = no
IF age = old AND credit_rating = fair THEN buys_computer = yes
38
39
40
41
Rule Induction: Sequential Covering Method
Sequential covering algorithm: Extracts rules directly from training
data
Typical sequential covering algorithms: FOIL, AQ, CN2, RIPPER
Rules are learned sequentially, each for a given class Ci will cover
many tuples of Ci but none (or few) of the tuples of other classes
Steps:
Rules are learned one at a time
Each time a rule is learned, the tuples covered by the rules are
removed
Repeat the process on the remaining tuples until termination
43
Building Classification Rules
Two approaches are used to build classification rules.
Direct Method
Extract rules directly from data. It is an inductive and sequential
approach.
Sequential Covering
Start from an empty rule
Grow a rule using the Learn-One-Rule function
Remove training records covered by the rule
Repeat Step (2) and (3) until stopping criterion is met
Aspects of Sequential Covering
Rule Growing
Instance Elimination
Rule Evaluation
Stopping Criterion
Rule Pruning
44
Rule Growing
CN2 Algorithm:
Start from an empty conjunct: {}
Add conjuncts that minimizes the entropy measure:
{A}, {A,B}, …
Determine the rule consequent by taking majority
class of instances covered by the rule
45
Rule Growing
RIPPER Algorithm:
Start from an empty rule: {} => class
measure:
R0: {} => class (initial rule)
Where,
t: number of positive instances covered by both R0 and R1
p0: number of positive instances covered by R0
n0: number of negative instances covered by R0
p1: number of positive instances covered by R1
n1: number of negative instances covered by R1
46
Instance Elimination
We need to eliminate instances otherwise; the next
rule is identical to previous rule.
We remove positive instances to ensure that the next
rule is different.
We remove negative instances to prevent
underestimating accuracy of rule
47
Rule Evaluation
48
Stopping Criterion and Rule Pruning
Stopping criterion
Compute the gain
Rule Pruning
Similar to post-pruning of decision trees.
pruning
If error improves, prune the conjunct
49
Indirect Method:
Extract rules from other classification models (e.g. decision
trees, neural networks, etc).
Eg; Rule Extraction from Decision Tree Refund
Yes No
Marital Status
Loan
Single Married
Refund Loan
<= 30K
>30K
Rules: No Loan Loan
R1: (Refund = Yes) => Loan
R2: (Refund = No) ^ (Marital Status = Married) => Loan
Rule simplification
Complex rules can be simplified. In above example R2 can be simplified as:
r2: (Marital Status = Married) => Loan
50
Advantages of Rule-Based Classifiers
As highly expressive as decision trees
Easy to interpret
Easy to generate
Can classify new instances rapidly
Performance comparable to decision trees
51
Chapter 3. Classification: Basic Concepts
52
Instance Based Classifier
•Rote-learner
• Memorizes entire training data and performs classification only if
attributes of record match one of the training examples exactly
•Nearest neighbor
53
Nearest neighbor
Nearest neighbor classifier requires:
Set of stored records
54
Issues of classification using k-nearest
neighbor classification
Choosing the value of K
One of challenge in classification is to choose the
vary.
55
Disadvantages
Poor accuracy when data have noise and irrelevant
attributes.
Slow when classifying test tuples.
Classifying unknown records are relatively expensive.
56
Chapter 3. Classification: Basic Concepts
57
Bayesian Classification: Why?
A statistical classifier: performs probabilistic prediction, i.e.,
predicts class membership probabilities
Foundation: Based on Bayes’ Theorem.
Performance: A simple Bayesian classifier, naïve Bayesian
classifier, has comparable performance with decision tree and
selected neural network classifiers
Incremental: Each training example can incrementally
increase/decrease the probability that a hypothesis is correct —
prior knowledge can be combined with observed data
Standard: Even when Bayesian methods are computationally
intractable, they can provide a standard of optimal decision
making against which other methods can be measured
58
Bayes’ Theorem: Basics
M
Total probability Theorem: P(B) P(B | Ai )P( Ai )
i 1
needs to be maximized
61
Naïve Bayes Classifier
A simplified assumption: attributes are conditionally
independent (i.e., no dependence relation between attributes):
n
P( X | C i ) P( x | C i ) P( x | C i ) P( x | C i ) ...P( x | C i )
k 1 2 n
k 1
62
Naïve Bayes Classifier
63
Naïve Bayes Classifier: Training Dataset
age income studentcredit_rating
buys_computer
<=30 high no fair no
Class: <=30 high no excellent no
C1:buys_computer = ‘yes’ 31…40 high no fair yes
C2:buys_computer = ‘no’ >40 medium no fair yes
>40 low yes fair yes
>40 low yes excellent no
Data to be classified: 31…40 low yes excellent yes
X = (age <=30, <=30 medium no fair no
Income = medium, <=30 low yes fair yes
Student = yes >40 medium yes fair yes
Credit_rating = Fair) <=30 medium yes excellent yes
31…40 medium no excellent yes
31…40 high yes fair yes
>40 medium no excellent no
64
Naïve Bayes Classifier: An Example age income studentcredit_rating
buys_comp
<=30 high no fair no
<=30 high no excellent no
31…40 high no fair yes
P(Ci): P(buys_computer = “yes”) = 9/14 = 0.643 >40
>40
>40
medium
low
low
no fair
yes fair
yes excellent
yes
yes
no
“uncorrected” counterparts 66
Naïve Bayes Classifier: Comments
Advantages
Easy to implement
Disadvantages
Assumption: class conditional independence, therefore loss of
accuracy
Practically, dependencies exist among variables
E.g., hospitals: patients: Profile: age, family history, etc.
Symptoms: fever, cough etc., Disease: lung cancer,
diabetes, etc.
Dependencies among these cannot be modeled by Naïve
Bayes Classifier
How to deal with these dependencies? Bayesian Belief Networks
(Chapter 9)
67
Chapter 3. Classification: Basic Concepts
68
Artificial Neural Network (ANN) Classifier
the problem. Two layers can be designed for complex problem. Number
of nodes in the hidden layer can be adjusted iteratively.
Number of output nodes/units: Depends upon number of class labels
During training the connection weights must be adjusted to fit i/p values
with the o/p values.
70
Back propagation algorithm
Step 1: Initialization:
Set all the weights and thresholds levels of the network to random numbers
uniformly distributed inside a small range.
Step 2: Activation:
Activate the back propagation neural network by applying i/ps and desired
o/ps.
Calculate the actual o/ps of the neurons in the hidden layers.
Calculate the actual o/ps of the neurons in the o/p layers.
Step 3: Weight training:
Updates weights in the back propagation network by propagating
backwards the errors associated with the o/p neurons.
Calculate error gradient of o/p layer and hence of neurons in the hidden
layer.
Step 4: Iteration:
Increase iteration by repeating steps 2 and 3 until selected error criteria is
satisfied.
71
Chapter 3. Classification: Basic Concepts
72
Model Evaluation and Selection
Evaluation metrics: How can we measure accuracy? Other
metrics to consider?
Use validation test set of class-labeled tuples instead of training
set when assessing accuracy
Methods for estimating a classifier’s accuracy:
Holdout method, random subsampling
Cross-validation
Bootstrap
Comparing classifiers:
Confidence intervals
Cost-benefit analysis and ROC Curves
73
Classifier Evaluation Metrics: Confusion
Matrix
Confusion Matrix:
Actual class\Predicted class C1 ¬ C1
C1 True Positives (TP) False Negatives (FN)
¬ C1 False Positives (FP) True Negatives (TN)
Fß: weighted measure of precision and recall
assigns ß times as much weight to recall as to precision
76
Classifier Evaluation Metrics: Example
77
78
79
Evaluating Classifier Accuracy:
Holdout & Cross-Validation Methods
Holdout method
Given data is randomly partitioned into two independent sets
Training set (e.g., 2/3) for model construction
Test set (e.g., 1/3) for accuracy estimation
Random sampling: a variation of holdout
Repeat holdout k times, accuracy = avg. of the accuracies
obtained
Cross-validation (k-fold, where k = 10 is most popular)
Randomly partition the data into k mutually exclusive subsets,
each approximately equal size
At i-th iteration, use Di as test set and others as training set
Leave-one-out: k folds where k = # of tuples, for small sized
data
*Stratified cross-validation*: folds are stratified so that class
dist. in each fold is approx. the same as that in the initial data
80
Model Selection: ROC Curves
ROC (Receiver Operating
Characteristics) curves: for visual
comparison of classification models
Originated from signal detection theory
Shows the trade-off between the true
positive rate and the false positive rate
The area under the ROC curve is a
Vertical axis
represents the true
measure of the accuracy of the model positive rate
Rank the test tuples in decreasing order: Horizontal axis rep.
the one that is most likely to belong to the false positive rate
the positive class appears at the top of The plot also shows a
the list diagonal line
The closer to the diagonal line (i.e., the A model with perfect
closer the area is to 0.5), the less accuracy will have an
accurate is the model area of 1.0
81
Issues Affecting Model Selection
Accuracy
classifier accuracy: predicting class label
Speed
time to construct the model (training time)
time to use the model (classification/prediction time)
Robustness: handling noise and missing values
Scalability: efficiency in disk-resident databases
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
82