Class: Rumale::EvaluationMeasure::Recall

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

Overview

Recall is a class that calculates the recall of the predicted labels.

Examples:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(average: 'binary') ⇒ Recall

Create a new evaluation measure calculater for recall score.

Parameters:

  • average (String) (defaults to: 'binary')

    The average type (‘binary’, ‘micro’, ‘macro’)



25
26
27
28
# File 'lib/rumale/evaluation_measure/recall.rb', line 25

def initialize(average: 'binary')
  check_params_string(average: average)
  @average = average
end

Instance Attribute Details

#averageString (readonly)

Return the average type for calculation of recall.

Returns:

  • (String)

    (‘binary’, ‘micro’, ‘macro’)



20
21
22
# File 'lib/rumale/evaluation_measure/recall.rb', line 20

def average
  @average
end

Instance Method Details

#score(y_true, y_pred) ⇒ Float

Calculate average recall

Parameters:

  • y_true (Numo::Int32)

    (shape: [n_samples]) Ground truth labels.

  • y_pred (Numo::Int32)

    (shape: [n_samples]) Predicted labels.

Returns:

  • (Float)

    Average recall



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rumale/evaluation_measure/recall.rb', line 35

def score(y_true, y_pred)
  check_label_array(y_true)
  check_label_array(y_pred)

  case @average
  when 'binary'
    recall_each_class(y_true, y_pred).last
  when 'micro'
    micro_average_recall(y_true, y_pred)
  when 'macro'
    macro_average_recall(y_true, y_pred)
  end
end