CSCI 4150: Introduction to Artificial Intelligence, Fall 2003 |
I believe the web tester assumes your code does this.
This, by the way, is the result of two conflicting notations: one from our text, and the other from the book "Numerical Recipes in C". I am trying to stick with the "Numerical Recipes in C" formulation.
Changes in version 1.3.1
[11/17] NEW VERSION: separates what was voting-data into voting-data1 and voting-data2
given a "tally", returns the majority attribute value
randomly picks "size" elements of "Lst". You can use this to select a training data set from a larger list.
takes 0 or more arguments and prints each to the screen.
((small ((expensive (red small furry)) (cheap (blue small furry)))) (large ((expensive (pink large furry)) (expensive (blue large furry)) (cheap (blue large smooth)))) (? ((cheap (red ? smooth)))))In order to treat the ? example as though it had the majority attribute value large, you can just add it to the list of examples for this value, i.e.
((small ((expensive (red small furry)) (cheap (blue small furry)))) (large ((expensive (pink large furry)) (expensive (blue large furry)) (cheap (blue large smooth)))) (cheap (red ? smooth)))))The rest of your code should pretty much be the same as the regular learn-dtree.
(majority-attribute-value tdata anames attribute)It will pick out the attribute value with the largest number of examples, excluding the ? attribute value. If the only attribute value in tdata is ?, then it returns '(). You can assume that you don't have to worry about this return value.