4 . 4
C OV E R I N G A LG O R I T H M S : C O N S T RU C T I N G RU L E S
1 0 9
Considering the possibilities for the unknown term ? yields the seven choices:
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
(Again, count the entries in Table 4.8.) The last is a clear winner, getting four
instances correct out of the six that it covers, and corresponds to the rule
If astigmatism
= yes and tear production rate = normal
then recommendation
= hard
Should we stop here? Perhaps. But let’s say we are going for exact rules, no
matter how complex they become.
Table 4.9 shows the cases that are covered by
the rule so far. The possibilities for the next term are now
age
= young
2/2
age
= pre-presbyopic
1/2
age
= presbyopic
1/2
spectacle prescription
= myope
3/3
spectacle prescription
= hypermetrope
1/3
We need to choose between the first and fourth. So far we have treated the frac-
tions numerically, but although these two are equal (both evaluate to 1), they
have different coverage: one selects just two correct instances and the other
Table 4.8
Part of the contact lens data for which astigmatism
= yes.
Age
Spectacle Astigmatism
Tear
production
Recommended
prescription
rate
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
P088407-Ch004.qxd 4/30/05 11:13 AM Page 109
selects three. In
the event of a tie, we choose the rule with the greater coverage,
giving the final rule:
If astigmatism
= yes and tear production rate = normal
and spectacle prescription
= myope then recommendation = hard
This is indeed one of the rules given for the contact lens problem. But it only
covers three of the four hard recommendations. So we delete these three from
the set of instances and start again, looking for another rule of the form:
If ? then recommendation
= hard
Following the same process, we will eventually find that age
=
young is the best
choice for the first term. Its coverage is seven; the reason for the seven is that 3
instances have been removed from the original set, leaving 21 instances alto-
gether. The best choice for the second term is astigmatism
= yes, selecting 1/3
(actually, this is a tie); tear production rate
= normal is the best for the third,
selecting 1/1.
If age
= young and astigmatism = yes and
tear production rate
= normal then recommendation = hard
This rule actually covers three of the original set of instances, two of which are
covered by the previous rule—but that’s all right because the recommendation
is the same for each rule.
Now that all the hard-lens cases are covered, the next step is to proceed with
the soft-lens ones in just the same way. Finally, rules are generated for the none
case—unless we are seeking a rule set with a default rule, in which case explicit
rules for the final outcome are unnecessary.
What we have just described is the PRISM method for constructing rules. It
generates only correct or “perfect” rules. It measures the success of a rule by the
accuracy formula p/t. Any rule with accuracy less than 100% is “incorrect” in
1 1 0
C H A P T E R 4
|
A LG O R I T H M S : T H E BA S I C M E T H O D S
Table 4.9
Part of the contact lens data for which astigmatism
= yes and tear
production rate
= normal.
Age
Spectacle Astigmatism
Tear
production
Recommended
prescription
rate
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
P088407-Ch004.qxd 4/30/05 11:13 AM Page 110