Module: SVMKit::Base::Classifier

Overview

Module for all classifiers in SVMKit.

Instance Method Summary collapse

Instance Method Details

#fitObject

An abstract method for fitting a model.

Raises:

  • (NotImplementedError)


11
12
13
# File 'lib/svmkit/base/classifier.rb', line 11

def fit
  raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
end

#predictObject

An abstract method for predicting labels.

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/svmkit/base/classifier.rb', line 16

def predict
  raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
end

#score(x, y) ⇒ Float

Calculate the mean accuracy of the given testing data.



25
26
27
28
29
30
31
# File 'lib/svmkit/base/classifier.rb', line 25

def score(x, y)
  SVMKit::Validation.check_sample_array(x)
  SVMKit::Validation.check_label_array(y)
  SVMKit::Validation.check_sample_label_size(x, y)
  evaluator = SVMKit::EvaluationMeasure::Accuracy.new
  evaluator.score(y, predict(x))
end