Professional Documents
Culture Documents
Chapter 8
Rule-Based Classification
Using IF-THEN Rules for
Classification
Rule-Based Classification
Using IF-THEN Rules for Classification
– where
◆ Condition (or LHS) is rule antecedent/precondition
◆ Conclusion (or RHS) is rule consequent
Rule-Based Classification
Using IF-THEN rules for classification
Rule-Based Classification
Assessment of a Rule
• Assessment of a rule:
– Coverage of a rule:
◆ The percentage of instances that satisfy the antecedent of a
rule (i.e., whose attribute values hold true for the rule’s
antecedent).
– Accuracy of a rule:
◆ The percentage of instances that satisfy both the antecedent
and consequent of a rule
Rule-Based Classification
Rule Coverage and Accuracy
• where
– D: class labeled data set
– |D|: number of instances in D
– ncovers : number of instances covered by R
– ncorrect : number of instances correctly classified by R
Rule-Based Classification
Example: AllElectronics
Rule-Based Classification
Coverage and Accuracy
Rule-Based Classification
Building Classification Rules
Rule-Based Classification
Direct Method
1R Algorithm
Rule-Based Classification
1R algorithm
• An easy way to find very simple classification rule
• 1R: rules that test one particular attribute
• Basic version
– One branch for each value
– Each branch assigns most frequent class
– Error rate: proportion of instances that don’t belong to the
majority class of their corresponding branch
– Choose attribute with lowest error rate (assumes nominal
attributes)
Rule-Based Classification
Pseudocode or 1R Algorithm
Rule-Based Classification
Example: The weather problem
Rule-Based Classification
Evaluating the weather attributes
Rule-Based Classification
The attribute with the smallest number of errors
Rule-Based Classification
Dealing with numeric attributes
Rule-Based Classification
Weather data with some numeric attributes
Rule-Based Classification
Example: temperature from weather data
Rule-Based Classification
The problem of overfitting
Rule-Based Classification
Minimum is set at 3 for temperature attribute
Rule-Based Classification
Sequential Covering Algorithms
Direct Method
Rule-Based Classification
Sequential Covering Algorithms
Rule-Based Classification
Sequential Covering Algorithms
• A sequential covering algorithm
Start from an empty rule
Grow a rule using the Learn-One-Rule function (Rule Growing)
Remove training records covered by the rule (Instance Elimination)
Repeat Step (2) and (3) until stopping criterion is met
(Optional) Rule Pruning
– .
Rule-Based Classification
Sequential Covering Algorithms
Instances covered
Instances covered by Rule 2
by Rule 1 Instances covered
by Rule 3
Instances
Rule-Based Classification
Basic Sequential Covering Algorithm
Rule-Based Classification
Basic Sequential Covering Algorithm
Rule-Based Classification
Basic Sequential Covering Algorithm
• Steps:
– Rules are learned one at a time
– Each time a rule is learned, the instances covered by
the rules are removed
– The process repeats on the remaining instances
unless termination condition
◆ e.g., when no more training examples or when the quality of a
rule returned is below a user-specified level
Rule-Based Classification
Rule Growing
Refund=No,
Status = Single
Refund=
No
Status =
Single
Status =
Divorced
Status =
Married
... Income
> 80K
(Class = Yes)
(b) Specific-to-general
Yes: 3 Yes: 2 Yes: 1 Yes: 0 Yes: 3
No: 4 No: 1 No: 0 No: 3 No: 1
(a) General-to-specific
Generating A Rule
Rule-Based Classification
Example: Generating A Rule
General-to- specific manner
• Example:
– Suppose our training set, D, consists of loan application
data.
– Attributes regarding each applicant include their:
◆ age
◆ income
◆ education level
◆ residence
◆ credit rating
◆ the term of the loan.
– The classifying attribute is loan_decision, which indicates
whether a loan is accepted (considered safe) or rejected
(considered risky).
Rule-Based Classification
Example: Generating A Rule
Rule-Based Classification
Example: Generating A Rule
Rule-Based Classification
Example: Generating A Rule
Rule-Based Classification
Example: Generating A Rule
Rule-Based Classification
Example: Generating A Rule
Rule-Based Classification
Example: Generating A Rule
Rule-Based Classification
P R I S M Algorithm
Rule-Based Classification
P R I S M Algorithm
Rule-Based Classification
Selecting a test
Rule-Based Classification
Example: contact lens data
Rule-Based Classification
Example: contact lens data
• Possible tests:
Rule-Based Classification
Create the rule
Rule-Based Classification
Further refinement
• Current state:
• Possible tests:
Rule-Based Classification
Modified rule and resulting data
Rule-Based Classification
Further refinement
• Current state:
• Possible tests:
Rule-Based Classification
The result
• Final rule:
Rule-Based Classification
Pseudo-code for P R I S M
Rule-Based Classification
Rules vs decision lists
Rule-Based Classification
Separate and conquer
Rule-Based Classification
Coverage or Accuracy?
Rule-Based Classification
Coverage or Accuracy?
Rule-Based Classification
Consider Both Coverage and Accuracy
Rule-Based Classification
FOIL Information Gain
• To generate a rule
while(true)
find the best predicate p
if FOIL_GAIN(p) > threshold then add p to current rule
else break
A3=1&&A1=2
A3=1&&A1=2
&&A8=5A3=1
Positive Negative
examples examples
Rule-Based Classification
Consider a training set that contains 100 positive examples and 400 negative examples.
For each of the following candidate rules,
R1 : A -> + (covers 4 positive and 1 negative examples),
R2 : B -> + (covers 30 positive and 10 negative examples),
R3 : C -> + (covers 100 positive and 90 negative examples),
determine which is the best and worst candidate rule according to:
nc
=
Accuracy n
nc + 1
Laplace =
n+k n : Total number of
instances
nc + kp
M-estimate = nc : Number of
n+k instances of class C
covered by rule
k : Number of classes
p : Prior probability
k
62
Stopping Criterion and Rule Pruning
Stopping criterion
pre-pruning
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
QUIZ 3