Class: FisherClassifier::Classifier
- Inherits:
-
Object
- Object
- FisherClassifier::Classifier
- Includes:
- Meta
- Defined in:
- lib/fisher_classifier/classifier.rb
Instance Method Summary collapse
- #classify(text) ⇒ Object
-
#initialize(config) ⇒ Classifier
constructor
A new instance of Classifier.
- #train(text, category) ⇒ Object
Methods included from Meta
Constructor Details
#initialize(config) ⇒ Classifier
6 7 8 |
# File 'lib/fisher_classifier/classifier.rb', line 6 def initialize(config) @config = config end |
Instance Method Details
#classify(text) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/fisher_classifier/classifier.rb', line 17 def classify(text) features = get_features(text) best = default_category max = 0.0 categories.each do |category| prob = fisher_prob(category, features) if prob > max best = category max = prob end end best end |
#train(text, category) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/fisher_classifier/classifier.rb', line 10 def train(text, category) get_features(text).each do |feature| inc_feature(feature, category) inc_category(category) end end |