Class: FisherClassifier::Classifier

Inherits:
Object
  • Object
show all
Includes:
Meta
Defined in:
lib/fisher_classifier/classifier.rb

Instance Method Summary collapse

Methods included from Meta

#meta_classify

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