Classification Algorithms – �Rules
Outline
2
Generating Rules
3
Covering algorithms
4
Example: generating a rule
5
If true then class = a |
Example: generating a rule, II
6
If x > 1.2 then class = a |
If true then class = a |
Example: generating a rule, III
7
If x > 1.2 then class = a |
If x > 1.2 and y > 2.6 then class = a |
If true then class = a |
Example: generating a rule, IV
8
If x > 1.2 then class = a |
If x > 1.2 and y > 2.6 then class = a |
If true then class = a |
If x ≤ 1.2 then class = b If x > 1.2 and y ≤ 2.6 then class = b |
Rules vs. trees
(produces exactly the same
predictions)
9
A simple covering algorithm
rule’s coverage:
10
Selecting a test
11
Example: contact lens data, 1
12
Age = Young | 2/8 |
Age = Pre-presbyopic | |
Age = Presbyopic | |
Spectacle prescription = Myope | |
Spectacle prescription = Hypermetrope | |
Astigmatism = no | |
Astigmatism = yes | |
Tear production rate = Reduced | |
Tear production rate = Normal | |
If ?� then recommendation = hard |
Example: contact lens data, 2
13
Age = Young | 2/8 |
Age = Pre-presbyopic | 1/8 |
Age = Presbyopic | 1/8 |
Spectacle prescription = Myope | 3/12 |
Spectacle prescription = Hypermetrope | 1/12 |
Astigmatism = no | 0/12 |
Astigmatism = yes | 4/12 |
Tear production rate = Reduced | 0/12 |
Tear production rate = Normal | 4/12 |
If ?� then recommendation = hard |
Modified rule and resulting data
14
Age | Spectacle prescription | Astigmatism | Tear production rate | Recommended lenses |
Young | Myope | Yes | Reduced | None |
Young | Myope | Yes | Normal | Hard |
Young | Hypermetrope | Yes | Reduced | None |
Young | Hypermetrope | Yes | Normal | hard |
Pre-presbyopic | Myope | Yes | Reduced | None |
Pre-presbyopic | Myope | Yes | Normal | Hard |
Pre-presbyopic | Hypermetrope | Yes | Reduced | None |
Pre-presbyopic | Hypermetrope | Yes | Normal | None |
Presbyopic | Myope | Yes | Reduced | None |
Presbyopic | Myope | Yes | Normal | Hard |
Presbyopic | Hypermetrope | Yes | Reduced | None |
Presbyopic | Hypermetrope | Yes | Normal | None |
If astigmatism = yes � then recommendation = hard |
Further refinement, 1
15
Age = Young | 2/4 |
Age = Pre-presbyopic | |
Age = Presbyopic | |
Spectacle prescription = Myope | |
Spectacle prescription = Hypermetrope | |
Tear production rate = Reduced | |
Tear production rate = Normal | |
If astigmatism = yes� and ? � then recommendation = hard |
Further refinement, 2
16
Age = Young | 2/4 |
Age = Pre-presbyopic | 1/4 |
Age = Presbyopic | 1/4 |
Spectacle prescription = Myope | 3/6 |
Spectacle prescription = Hypermetrope | 1/6 |
Tear production rate = Reduced | 0/6 |
Tear production rate = Normal | 4/6 |
If astigmatism = yes� and ? � then recommendation = hard |
Modified rule and resulting data
17
Age | Spectacle prescription | Astigmatism | Tear production rate | Recommended lenses |
Young | Myope | Yes | Normal | Hard |
Young | Hypermetrope | Yes | Normal | hard |
Pre-presbyopic | Myope | Yes | Normal | Hard |
Pre-presbyopic | Hypermetrope | Yes | Normal | None |
Presbyopic | Myope | Yes | Normal | Hard |
Presbyopic | Hypermetrope | Yes | Normal | None |
If astigmatism = yes� and tear production rate = normal � then recommendation = hard |
Further refinement, 3
18
Age = Young | |
Age = Pre-presbyopic | |
Age = Presbyopic | |
Spectacle prescription = Myope | |
Spectacle prescription = Hypermetrope | |
If astigmatism = yes � and tear production rate = normal� and ?�then recommendation = hard |
Further refinement, 4
19
Age = Young | 2/2 |
Age = Pre-presbyopic | 1/2 |
Age = Presbyopic | 1/2 |
Spectacle prescription = Myope | 3/3 |
Spectacle prescription = Hypermetrope | 1/3 |
If astigmatism = yes � and tear production rate = normal� and ?�then recommendation = hard |
The result
20
If astigmatism = yes�and tear production rate = normal�and spectacle prescription = myope�then recommendation = hard |
If age = young and astigmatism = yes�and tear production rate = normal�then recommendation = hard |
Pseudo-code for PRISM
21
For each class C Initialize E to the instance set While E contains instances in class C Create a rule R with an empty left-hand side that predicts class C Until R is perfect (or there are no more attributes to use) do For each attribute A not mentioned in R, and each value v, Consider adding the condition A = v to the left-hand side of R Select A and v to maximize the accuracy p/t (break ties by choosing the condition with the largest p) Add A = v to R Remove the instances covered by R from E |
Rules vs. decision lists
22
Separate and conquer
23
Conclusions
24