-
Notifications
You must be signed in to change notification settings - Fork 31
/
classifier.rb
36 lines (31 loc) · 1.05 KB
/
classifier.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true
require 'rumale/validation'
require 'rumale/evaluation_measure/accuracy'
module Rumale
module Base
# Module for all classifiers in Rumale.
module Classifier
include Validation
# 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)
check_sample_array(x)
check_label_array(y)
check_sample_label_size(x, y)
evaluator = Rumale::EvaluationMeasure::Accuracy.new
evaluator.score(y, predict(x))
end
end
end
end