Class: Rumale::EvaluationMeasure::Accuracy

Inherits:
Object
  • Object
show all
Includes:
Base::Evaluator
Defined in:
rumale-evaluation_measure/lib/rumale/evaluation_measure/accuracy.rb

Overview

Accuracy is a class that calculates the accuracy of classifier from the predicted labels.

Examples:

require 'rumale/evaluation_measure/accuracy'

evaluator = Rumale::EvaluationMeasure::Accuracy.new
puts evaluator.score(ground_truth, predicted)

Instance Method Summary collapse

Instance Method Details

#score(y_true, y_pred) ⇒ Float

Calculate mean accuracy.

Parameters:

  • y_true (Numo::Int32)

    (shape: [n_samples]) Ground truth labels.

  • y_pred (Numo::Int32)

    (shape: [n_samples]) Predicted labels.

Returns:

  • (Float)

    Mean accuracy



22
23
24
# File 'rumale-evaluation_measure/lib/rumale/evaluation_measure/accuracy.rb', line 22

def score(y_true, y_pred)
  (y_true.to_a.map.with_index { |label, n| label == y_pred[n] ? 1 : 0 }).sum / y_true.size.to_f
end