Module: Stamina::Classifier

Included in:
Automaton
Defined in:
lib/stamina/classifier.rb

Overview

Provides a reusable module for binary classifiers. Classes including this module are required to provide a label_of(string) method, returning ‘1’ for strings considered positive, and ‘0’ fr strings considered negative.

Note that an Automaton being a classifier it already includes this module.

Instance Method Summary collapse

Instance Method Details

#correctly_classify?(sample) ⇒ Boolean

Checks if a labeled sample is correctly classified by the classifier.

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
# File 'lib/stamina/classifier.rb', line 27

def correctly_classify?(sample)
  sample.each do |str|
    label = label_of(str)
    expected = (str.positive? ? '1' : '0')
    return false unless expected==label
  end
  true
end

#signature(sample) ⇒ Object

Computes a signature for a given sample (that is, an ordered set of strings). The signature is a string containing 1 (considered positive, or accepted) and 0 (considered negative, or rejected), one for each string.



16
17
18
19
20
21
22
# File 'lib/stamina/classifier.rb', line 16

def signature(sample)
  signature = ''
  sample.each do |str|
    signature << label_of(str)
  end
  signature
end