@@ -166,7 +166,7 @@ class NaiveBayesLearner(Learner):
166
166
167
167
def train (self , dataset ):
168
168
"""Just count the target/attr/val occurrences.
169
- Count how many times each value of each attribute occurs.
169
+ Count how many times each value of each input attribute occurs.
170
170
Store count in N[targetvalue][attr][val]. Let
171
171
N[targetvalue][attr][None] be the sum over all vals."""
172
172
self .dataset = dataset
@@ -331,7 +331,8 @@ def all_same_class(self, examples):
331
331
332
332
def choose_attribute (self , attrs , examples ):
333
333
"Choose the attribute with the highest information gain."
334
- return argmax (attrs , lambda a : self .information_gain (a , examples ))
334
+ return argmax_random_tie (attrs ,
335
+ lambda a : self .information_gain (a , examples ))
335
336
336
337
def information_gain (self , attr , examples ):
337
338
def I (examples ):
@@ -539,8 +540,9 @@ def T(attrname, branches):
539
540
__doc__ += """
540
541
[Fig. 18.6]
541
542
>>> restaurant_learner = DecisionTreeLearner()
543
+ >>> random.seed(437)
542
544
>>> restaurant_learner.train(restaurant)
543
- >>> restaurant_learner.dt.display() #doctest:+ELLIPSIS
545
+ >>> restaurant_learner.dt.display()
544
546
Test Patrons
545
547
Patrons = None ==> RESULT = No
546
548
Patrons = Full ==> Test Hungry
@@ -549,7 +551,7 @@ def T(attrname, branches):
549
551
Type = Thai ==> Test Fri/Sat
550
552
Fri/Sat = Yes ==> RESULT = Yes
551
553
Fri/Sat = No ==> RESULT = No
552
- Type = French ==> RESULT = ...
554
+ Type = French ==> RESULT = Yes
553
555
Type = Italian ==> RESULT = No
554
556
Hungry = No ==> RESULT = No
555
557
Patrons = Some ==> RESULT = Yes
0 commit comments