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)


8
9
10
# File 'lib/svmkit/base/classifier.rb', line 8

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

#predictObject

An abstract method for predicting labels.

Raises:

  • (NotImplementedError)


13
14
15
# File 'lib/svmkit/base/classifier.rb', line 13

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

#score(x, y) ⇒ Float

Claculate the mean accuracy of the given testing data.

Parameters:

  • x (Numo::DFloat)

    (shape: [n_samples, n_features]) Testing data.

  • y (Numo::Int32)

    (shape: [n_samples]) True labels for testing data.

Returns:

  • (Float)

    Mean accuracy



22
23
24
25
# File 'lib/svmkit/base/classifier.rb', line 22

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