0% found this document useful (0 votes)
8 views82 pages

Classification Algorithms Overview

a note on data mining ioe attached for the ioe exam, TU KEC KANTIPUR ENGINEERING COLLEGE , DHAPAKHEL Binod Wosti

Uploaded by

akafle99
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views82 pages

Classification Algorithms Overview

a note on data mining ioe attached for the ioe exam, TU KEC KANTIPUR ENGINEERING COLLEGE , DHAPAKHEL Binod Wosti

Uploaded by

akafle99
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

Chapter 3.

Classification: Basic Concepts

 Classification: Basic Concepts


 Decision Tree classifier
 Rule Based Classifier
 Nearest Neighbor Classifier
 Bayesian Classifier
 Artificial Neural Network (ANN) Classifier
 Model Evaluation and Selection

1
Concept of Classification

2
Concept of Classification

Training data

Model Model Apply


Conceptual Learning Evaluation Model
Model

Training Test Data


Algorithm

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

determined by the class label attribute


 The set of tuples used for model construction is training set

 The model is represented as classification rules, decision trees, or

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

NAME RANK YEARS TENURED Classifier


Mike Assistant Prof 3 no (Model)
Mary Assistant Prof 7 yes
Bill Professor 2 yes
Jim Associate Prof 7 yes IF rank = ‘professor’
Dave Assistant Prof 6 no
OR years > 6
Anne Associate Prof 3 no
THEN tenured = ‘yes’
5
Process (2): Using the Model in Prediction

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

student? yes credit rating?

no yes excellent fair

no yes no yes
9
Decision Tree Algorithm
 Hunt’s Algorithm

 ID3, J48, C4.5 (Based on Entropy Calculation)

 SLIQ,SPRINT,CART (Based on Gini-Index)

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

 Attributes are categorical (if continuous-valued, they are

discretized in advance)
 Examples are partitioned recursively based on selected

attributes
 Test attributes are selected on the basis of a heuristic or

statistical measure (e.g., information gain)


 Conditions for stopping partitioning
 All samples for a given node belong to the same class

 There are no remaining attributes for further partitioning –

majority voting is employed for classifying the leaf


 There are no samples left
17
ID3 Algorithm
 The ID3 algorithm begins with the original dataset as the
root node.
 On each iteration of the algorithm, it iterates through every
unused attribute of the dataset and calculates the
entropy (or information gain ) of that attribute.
 It then selects the attribute which has the smallest entropy
(or largest information gain) value.
 The dataset is then split by the selected attribute to produce
subsets of the data.
 The algorithm continues to recur on each subset,
considering only attributes never selected before.
Recursion on a subset may stop in one of these cases:
18
ID3 Algorithm
 Every element in the subset belongs to the same class , then the
node is turned into a leaf and labeled with the class of the
examples
 If the examples do not belong to the same class ,

 Calculate entropy and hence information gain to select the best

node to split data.


 Partition the data into subset.

 Recursively repeat until all data are correctly classified

Throughout the algorithm, the decision tree is constructed with


each non-terminal node representing the selected attribute on
which the data was split, and terminal nodes representing the
class label of the final subset of this branch.

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 |

 Information gained by branching on attribute A


Gain(A) Info(D)  Info A(D)
24
Attribute Selection: Information Gain
 Class P: buys_computer = “yes” 5 4
Infoage ( D )  I (2,3)  I (4,0)
 Class N: buys_computer = “no” 14 14
9 9 5 5 5
Info( D) I (9,5)  log 2 ( )  log 2 ( ) 0.940  I (3,2) 0.694
14 14 14 14 14
age pi ni I(p i, n i) 5
<=30 2 3 0.971 I (2,3) means “age <=30” has 5 out of
14
31…40 4 0 0 14 samples, with 2 yes’es and 3
>40 3 2 0.971 no’s. Hence
age
<=30
income student credit_rating
high no fair
buys_computer
no
Gain(age) Info( D )  Infoage ( D ) 0.246
<=30 high no excellent no
31…40 high no fair yes
>40 medium no fair yes Similarly,
>40 low yes fair yes
>40 low yes excellent no
31…40 low yes excellent yes Gain(income) 0.029
<=30 medium no fair no
<=30
>40
low
medium
yes
yes
fair
fair
yes
yes
Gain( student ) 0.151
<=30
31…40
medium
medium
yes
no
excellent
excellent
yes
yes Gain(credit _ rating ) 0.048
31…40 high yes fair yes
>40 medium no excellent no 25
Computing Information-Gain for
Continuous-Valued Attributes
 Let attribute A be a continuous-valued attribute
 Must determine the best split point for A
 Sort the value A in increasing order
 Typically, the midpoint between each pair of adjacent values
is considered as a possible split point
 (ai+ai+1)/2 is the midpoint between the values of ai and ai+1
 The point with the minimum expected information
requirement for A is selected as the split-point for A
 Split:
 D1 is the set of tuples in D satisfying A ≤ split-point, and D2
is the set of tuples in D satisfying A > split-point
26
Gain Ratio for Attribute Selection (C4.5)

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.

 gain_ratio(income) = 0.029/1.557 = 0.019


 The attribute with the maximum gain ratio is selected as the
splitting attribute
28
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)
29
Computation of Gini Index
 Ex. D has 9 tuples in buys_computer = “yes”
2
and
2
5 in “no”
 9  5
gini ( D) 1       0.459
 14   14 
 Suppose the attribute income partitions D into 10 in D1: {low,
 10   4
medium} and 4 in D2 giniincome{low,medium} ( D)  14 Gini( D1 )   14 Gini( D2 )
   

Gini{low,high} is 0.458; Gini{medium,high} is 0.450. Thus, split on the


{low,medium} (and {high}) since it has the lowest Gini index
 All attributes are assumed continuous-valued
 May need other tools, e.g., clustering, to get the possible split
values
 30
Comparing Attribute Selection Measures

 The three measures, in general, return good results but


 Information gain:

biased towards multivalued attributes
 Gain ratio:

tends to prefer unbalanced splits in which one partition is
much smaller than the others
 Gini index:

biased to multivalued attributes

has difficulty when # of classes is large

tends to favor tests that result in equal-sized partitions and
purity in both partitions
31
Overfitting and Tree Pruning
 Overfitting: An induced tree may overfit the training data
 Too many branches, some may reflect anomalies due to noise

or outliers
 Poor accuracy for unseen samples

 Two approaches to avoid overfitting


 Prepruning: Halt tree construction early ̵ do not split a node

if this would result in the goodness measure falling below a


threshold

Difficult to choose an appropriate threshold
 Postpruning: Remove branches from a “fully grown” tree—

get a sequence of progressively pruned trees



Use a set of data different from the training data to decide
which is the “best pruned tree” 32
Enhancements to Basic Decision Tree Induction

 Allow for continuous-valued attributes


 Dynamically define new discrete-valued attributes that
partition the continuous attribute value into a discrete set of
intervals
 Handle missing attribute values
 Assign the most common value of the attribute
 Assign probability to each of the possible values
 Attribute construction
 Create new attributes based on existing ones that are sparsely
represented
 This reduces fragmentation, repetition, and replication
33
Advantages of Decision Tree Classifier
 Inexpensive to construct
 Extremely fast at classifying unknown records
 Easy to interpret for small-sized trees

34
35
Chapter 3. Classification: Basic Concepts

 Classification: Basic Concepts


 Decision Tree classifier
 Rule Based Classifier
 Nearest Neighbor Classifier
 Bayesian Classifier
 Artificial Neural Network (ANN) Classifier
 Model Evaluation and Selection

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

condition, e.g., when no more training examples or when the


quality of a rule returned is below a user-specified threshold
 Comp. w. decision-tree induction: learning a set of rules
simultaneously
42
Characteristics of Rule-Based
Classifier
 Mutually exclusive Rules
 Classifier contains mutually exclusive rules if all the rules are

independent of each other.


 Every record is covered by at most one rule.

 Rules are no longer mutually exclusive if a record may triggered by

more than one rule. To make mutually exclusive we apply rule


ordering.
 Exhaustive Rules
 Classifier has exhaustive coverage if it accounts for every possible

combination of attribute values (every possible rule).


 Each record is covered by at least one rule.

 Rules are no longer exhaustive if a record may not trigger any

rules. To make rules exhaustive use default class.

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

 Add conjuncts that maximize FOIL’s information gain

measure:
 R0: {} => class (initial rule)

 R1: {A} => class (rule after adding conjunct)

 Gain (R0, R1) = t [ log (p1/(p1+n1)) – log (p0/(p0 + n0)) ]

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

 If gain is not significant, discard the new rule.

 Rule Pruning
 Similar to post-pruning of decision trees.

 Reduced Error Pruning:

 Remove one of the conjuncts in the rule

 Compare error rate on validation set before and after

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

 Classification: Basic Concepts


 Decision Tree classifier
 Rule Based Classifier
 Nearest Neighbor Classifier
 Bayesian Classifier
 Artificial Neural Network (ANN) Classifier
 Model Evaluation and Selection

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

• Uses k “closest” points (nearest neighbors) for performing classification.


K-closet neighbor of a record ‘X’ are data points that have the K-smallest
distance of ‘X’.
• Classification based on learning by analogy i.e. by comparing a given test
tuple with training tuple that are similar to it.
• Training tuples are described by n-attributes.
• When given an unknown tuple, a k-nearest- neighbor classifier searches
the pattern space for the k-training tuples that are closest to the
unknown tuple.

53
Nearest neighbor
 Nearest neighbor classifier requires:
 Set of stored records

 Distance metric to compute distance between records. For

distance calculation any standard approach can be used


such as Euclidean distance.
 The value of ‘K’, the number of nearest neighbor to retrieve.

 To classify the unknown records

 Compute distance to other training records.

 Identify the k-nearest neighbor.

 Use class label nearest neighbors to determine the class

label of unknown record. In case of conflict, use majority


vote for classification.

54
Issues of classification using k-nearest
neighbor classification
 Choosing the value of K
 One of challenge in classification is to choose the

appropriate value of K. If K is too small, it is sensitive to


noise points. If K is too large, neighbor may include points
from other classes.
 With the change of value of K, the classification result may

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

 Classification: Basic Concepts


 Decision Tree classifier
 Rule Based Classifier
 Nearest Neighbor Classifier
 Bayesian Classifier
 Artificial Neural Network (ANN) Classifier
 Model Evaluation and Selection

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

 Bayes’ Theorem: P( H | X) P(X | H ) P( H ) P(X | H )P( H ) / P(X)


P(X)
 Let X be a data sample (“evidence”): class label is unknown
 Let H be a hypothesis that X belongs to class C
 Classification is to determine P(H|X), (i.e., posteriori probability): the
probability that the hypothesis holds given the observed data sample X
 P(H) (prior probability): the initial probability

E.g., X will buy computer, regardless of age, income, …
 P(X): probability that sample data is observed
 P(X|H) (likelihood): the probability of observing the sample X, given that
the hypothesis holds

E.g., Given that X will buy computer, the prob. that X is 31..40,
medium income
59
Prediction Based on Bayes’ Theorem
 Given training data X, posteriori probability of a hypothesis H,
P(H|X), follows the Bayes’ theorem

P(H | X) P(X | H ) P( H ) P(X | H )P( H ) / P(X)


P(X)
 Informally, this can be viewed as
posteriori = likelihood x prior/evidence
 Predicts X belongs to Ci iff the probability P(Ci|X) is the highest
among all the P(Ck|X) for all the k classes
 Practical difficulty: It requires initial knowledge of many
probabilities, involving significant computational cost
60
Classification Is to Derive the Maximum Posteriori
 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’ theoremP(X | C )P(C )
P(C | X)  i i
i P(X)

 Since P(X) is constant for allP(classes,


C | X) only
P(X | C )P(C )
i i i

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

P(buys_computer = “no”) = 5/14= 0.357 31…40


<=30
low
medium
yes excellent
no fair
yes
no
<=30 low yes fair yes

Compute P(X|Ci) for each class >40
<=30
medium yes fair
medium yes excellent
yes
yes
31…40 medium no excellent yes

P(age = “<=30” | buys_computer = “yes”) = 2/9 = 0.222 31…40


>40
high
medium
yes fair
no excellent
yes
no

P(age = “<= 30” | buys_computer = “no”) = 3/5 = 0.6


P(income = “medium” | buys_computer = “yes”) = 4/9 = 0.444
P(income = “medium” | buys_computer = “no”) = 2/5 = 0.4
P(student = “yes” | buys_computer = “yes) = 6/9 = 0.667
P(student = “yes” | buys_computer = “no”) = 1/5 = 0.2
P(credit_rating = “fair” | buys_computer = “yes”) = 6/9 = 0.667
P(credit_rating = “fair” | buys_computer = “no”) = 2/5 = 0.4
 X = (age <= 30 , income = medium, student = yes, credit_rating = fair)
P(X|Ci) : P(X|buys_computer = “yes”) = 0.222 x 0.444 x 0.667 x 0.667 = 0.044
P(X|buys_computer = “no”) = 0.6 x 0.4 x 0.2 x 0.4 = 0.019
P(X|Ci)*P(Ci) : P(X|buys_computer = “yes”) * P(buys_computer = “yes”) = 0.028
P(X|buys_computer = “no”) * P(buys_computer = “no”) = 0.007
Therefore, X belongs to class (“buys_computer = yes”) 65
Avoiding the Zero-Probability Problem
 Naïve Bayesian prediction requires each conditional prob. be
non-zero. Otherwise, the predicted prob. will be zero
n
P( X | C i)   P( x k | C i)
k 1
 Ex. Suppose a dataset with 1000 tuples, income=low (0),
income= medium (990), and income = high (10)
 Use Laplacian correction (or Laplacian estimator)
 Adding 1 to each case

Prob(income = low) = 1/1003


Prob(income = medium) = 991/1003
Prob(income = high) = 11/1003
 The “corrected” prob. estimates are close to their

“uncorrected” counterparts 66
Naïve Bayes Classifier: Comments
 Advantages
 Easy to implement

 Good results obtained in most of the cases

 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

 Classification: Basic Concepts


 Decision Tree classifier
 Rule Based Classifier
 Nearest Neighbor Classifier
 Bayesian Classifier
 Artificial Neural Network (ANN) Classifier
 Model Evaluation and Selection

68
Artificial Neural Network (ANN) Classifier

 It is set of connected i/o units in which each connection has a


weight associated with it.
 During the learning phase the network learns by adjusting the
weights so as to be able to predict the correct class label of i/p
labels.
 It also referred as connectionist learning due to connection
between units.
 It has long training time and poor interpretability but has
tolerance to noisy data.
 It can classify pattern on which they have not been trained.
 Well suited for continuous valued i/ps.
 It has parallel topology and processing.
69
Artificial Neural Network (ANN) Classifier

 Before training the network topology must be designed by:


 Specifying number of i/p nodes/units: Depends upon number of

independent variable in data set.


 Number of hidden layers: Generally only layer is considered in most of

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

of the data set.


 Learning rate: Can be adjusted iteratively.

 Learning algorithm: Any appropriate learning algorithm can be


selected during training phase.
 Bias value: Can be adjusted iteratively.

 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

 Classification: Basic Concepts


 Decision Tree classifier
 Rule Based Classifier
 Nearest Neighbor Classifier
 Bayesian Classifier
 Artificial Neural Network (ANN) Classifier
 Model Evaluation and Selection

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)

Example of Confusion Matrix:


Actual class\Predicted buy_computer buy_computer Total
class = yes = no
buy_computer = yes 6954 46 7000
buy_computer = no 412 2588 3000
Total 7366 2634 10000
 Given m classes, an entry, CMi,j in a confusion matrix indicates
# of tuples in class i that were labeled by the classifier as class j
 May have extra rows/columns to provide totals
74
Classifier Evaluation Metrics: Accuracy, Error
Rate, Sensitivity and Specificity
A\P C ¬C  Class Imbalance Problem:
C TP FN P  One class may be rare, e.g.
¬C FP TN N
fraud, or HIV-positive
P’ N’ All
 Significant majority of the

 Classifier Accuracy, or negative class and minority of


recognition rate: percentage of the positive class
test set tuples that are correctly  Sensitivity: True Positive

classified recognition rate


Accuracy = (TP + TN)/All 
Sensitivity = TP/P
 Error rate: 1 – accuracy, or  Specificity: True Negative

Error rate = (FP + FN)/All recognition rate



Specificity = TN/N
75
Classifier Evaluation Metrics:
Precision and Recall, and F-measures
 Precision: exactness – what % of tuples that the classifier
labeled as positive are actually positive

 Recall: completeness – what % of positive tuples did the


classifier label as positive?
 Perfect score is 1.0
 Inverse relationship between precision & recall

F measure (F1 or F-score): harmonic mean of precision and
recall,


Fß: weighted measure of precision and recall

assigns ß times as much weight to recall as to precision

76
Classifier Evaluation Metrics: Example

Actual Class\Predicted class cancer = yes cancer = no Total Recognition(%)


cancer = yes 90 210 300 30.00 (sensitivity
cancer = no 140 9560 9700 98.56 (specificity)
Total 230 9770 10000 96.40 (accuracy)
 Precision = 90/230 = 39.13% Recall = 90/300 = 30.00%

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

You might also like