lib/svmkit/base/classifier.rb in svmkit-0.2.5 vs lib/svmkit/base/classifier.rb in svmkit-0.2.6
- old
+ new
@@ -1,5 +1,6 @@
+# frozen_string_literal: true
module SVMKit
module Base
# Module for all classifiers in SVMKit.
module Classifier
@@ -11,12 +12,17 @@
# An abstract method for predicting labels.
def predict
raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
end
- # An abstract method for calculating classification accuracy.
- def score
- raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
+ # Claculate the mean accuracy of the given testing data.
+ #
+ # @param x [Numo::DFloat] (shape: [n_samples, n_features]) Testing data.
+ # @param y [Numo::Int32] (shape: [n_samples]) True labels for testing data.
+ # @return [Float] Mean accuracy
+ def score(x, y)
+ evaluator = SVMKit::EvaluationMeasure::Accuracy.new
+ evaluator.score(y, predict(x))
end
end
end
end