Sha256: 26da4c35cb072e869fd1cf8ea80b80f763fb32293127a5a2048617a36e9dd181

Contents?: true

Size: 1.08 KB

Versions: 17

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'svmkit/validation'
require 'svmkit/evaluation_measure/accuracy'

module SVMKit
  module Base
    # Module for all classifiers in SVMKit.
    module Classifier
      # An abstract method for fitting a model.
      def fit
        raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
      end

      # An abstract method for predicting labels.
      def predict
        raise NotImplementedError, "#{__method__} has to be implemented in #{self.class}."
      end

      # Calculate 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)
        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
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
svmkit-0.7.3 lib/svmkit/base/classifier.rb
svmkit-0.7.2 lib/svmkit/base/classifier.rb
svmkit-0.7.1 lib/svmkit/base/classifier.rb
svmkit-0.7.0 lib/svmkit/base/classifier.rb
svmkit-0.6.3 lib/svmkit/base/classifier.rb
svmkit-0.6.2 lib/svmkit/base/classifier.rb
svmkit-0.6.1 lib/svmkit/base/classifier.rb
svmkit-0.6.0 lib/svmkit/base/classifier.rb
svmkit-0.5.2 lib/svmkit/base/classifier.rb
svmkit-0.5.1 lib/svmkit/base/classifier.rb
svmkit-0.5.0 lib/svmkit/base/classifier.rb
svmkit-0.4.1 lib/svmkit/base/classifier.rb
svmkit-0.4.0 lib/svmkit/base/classifier.rb
svmkit-0.3.3 lib/svmkit/base/classifier.rb
svmkit-0.3.2 lib/svmkit/base/classifier.rb
svmkit-0.3.1 lib/svmkit/base/classifier.rb
svmkit-0.3.0 lib/svmkit/base/classifier.rb