Class: Ai4r::Classifiers::Classifier
- Inherits:
-
Object
- Object
- Ai4r::Classifiers::Classifier
- Includes:
- Data::Parameterizable
- Defined in:
- lib/ai4r/classifiers/classifier.rb
Overview
This class defines a common API for classifiers. All methods in this class must be implemented in subclasses.
Direct Known Subclasses
Hyperpipes, ID3, MultilayerPerceptron, NaiveBayes, OneR, Prism, ZeroR
Instance Method Summary collapse
-
#build(data_set) ⇒ Object
Build a new classifier, using data examples found in data_set.
-
#eval(data) ⇒ Object
You can evaluate new data, predicting its class.
-
#get_rules ⇒ Object
This method returns the generated rules in ruby code.
Methods included from Data::Parameterizable
#get_parameters, included, #set_parameters
Instance Method Details
#build(data_set) ⇒ Object
Build a new classifier, using data examples found in data_set. The last attribute of each item is considered as the item class.
24 25 26 |
# File 'lib/ai4r/classifiers/classifier.rb', line 24 def build(data_set) raise NotImplementedError end |
#eval(data) ⇒ Object
You can evaluate new data, predicting its class. e.g.
classifier.eval(['New York', '<30', 'F']) # => 'Y'
31 32 33 |
# File 'lib/ai4r/classifiers/classifier.rb', line 31 def eval(data) raise NotImplementedError end |
#get_rules ⇒ Object
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)' and city=='Chicago' then marketing_target='Y'
elsif age_range=='[30-50)' and city=='New York' then marketing_target='N'
elsif age_range=='[50-80]' then marketing_target='N'
elsif age_range=='>80' then marketing_target='Y'
else raise 'There was not enough information during training to do a proper induction for this data element' end
It is a nice way to inspect induction results, and also to execute them:
age_range = '<30'
city='New York'
marketing_target = nil
eval classifier.get_rules
puts marketing_target
# => 'Y'
53 54 55 |
# File 'lib/ai4r/classifiers/classifier.rb', line 53 def get_rules raise NotImplementedError end |