def NaiveBayesLearner(dataset):
targetvals = dataset.values[dataset.target]<EOL>target_dist = CountingProbDist(targetvals)<EOL>attr_dists = dict(((gv, attr), CountingProbDist(dataset.values[attr]))<EOL>for gv in targetvals<EOL>for attr in dataset.inputs)<EOL>for example in dataset.examples:<EOL><INDENT>targetval = example[dataset.target]<EOL>target_dist.add(targetval)<EOL>for attr in dataset.inputs:<EOL><INDENT>attr_dists[targetval, attr].add(example[attr])<EOL><DEDENT><DEDENT>def predict(example):<EOL><INDENT>"""<STR_LIT>"""<EOL>def class_probability(targetval):<EOL><INDENT>return (target_dist[targetval]<EOL>* product(attr_dists[targetval, attr][example[attr]]<EOL>for attr in dataset.inputs))<EOL><DEDENT>return argmax(targetvals, class_probability)<EOL><DEDENT>return predict<EOL>
Just count how many times each value of each input attribute
    occurs, conditional on the target value. Count the different
    target values too.