Classifier
The idea behind the ZeroR classifier is to identify the the most common class value in the training set. It always returns that value when evaluating an instance. It is frequently used as a baseline for evaluating other machine learning algorithms.
Build a new ZeroR classifier. You must provide a DataSet instance as parameter. The last attribute of each item is considered as the item class.
# File lib/ai4r/classifiers/zero_r.rb, line 30 def build(data_set) data_set.check_not_empty @data_set = data_set frequence = {} max_freq = 0 @class_value = nil @data_set.data_items.each do |example| class_value = example.last class_frequency = frequence[class_value] class_frequency = (class_frequency) ? class_frequency+1 : 1 if max_freq < class_frequency max_freq = class_frequency @class_value = class_value end end return self end
You can evaluate new data, predicting its class. e.g.
classifier.eval(['New York', '<30', 'F']) # => 'Y'
# File lib/ai4r/classifiers/zero_r.rb, line 51 def eval(data) @class_value end
This method returns the generated rules in ruby code. e.g.
classifier.get_rules # => marketing_target='Y'
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'
# File lib/ai4r/classifiers/zero_r.rb, line 66 def get_rules return "#{@data_set.data_labels.last} = '#{@class_value}'" end
Generated with the Darkfish Rdoc Generator 2.