| Class | Ai4r::Classifiers::OneR |
| In: |
lib/ai4r/classifiers/one_r.rb
|
| Parent: | Classifier |
The idea of the OneR algorithm is identify the single attribute to use to classify data that makes fewest prediction errors. It generates rules based on a single attribute.
| data_set | [R] | |
| rule | [R] |
Build a new OneR classifier. You must provide a DataSet instance as parameter. The last attribute of each item is considered as the item class.
You can evaluate new data, predicting its class. e.g.
classifier.eval(['New York', '<30', 'F']) # => 'Y'
This method returns the generated rules in ruby code. e.g.
classifier.get_rules
# => if age_range == '<30' then marketing_target = 'Y'
elsif age_range == '[30-50)' then marketing_target = 'N'
elsif age_range == '[50-80]' then marketing_target = 'N'
end
It is a nice way to inspect induction results, and also to execute them:
marketing_target = nil
eval classifier.get_rules
puts marketing_target
# => 'Y'