Sha256: f0ebcfbd3207751458e89e7419e6360b0d0ab42a50d77ecefa00875d04cc8711

Contents?: true

Size: 1.51 KB

Versions: 29

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require 'rumale/base/evaluator'
require 'rumale/evaluation_measure/precision_recall'

module Rumale
  # This module consists of the classes for model evaluation.
  module EvaluationMeasure
    # Recall is a class that calculates the recall of the predicted labels.
    #
    # @example
    #   evaluator = Rumale::EvaluationMeasure::Recall.new
    #   puts evaluator.score(ground_truth, predicted)
    class Recall
      include Base::Evaluator
      include EvaluationMeasure::PrecisionRecall

      # Return the average type for calculation of recall.
      # @return [String] ('binary', 'micro', 'macro')
      attr_reader :average

      # Create a new evaluation measure calculater for recall score.
      #
      # @param average [String] The average type ('binary', 'micro', 'macro')
      def initialize(average: 'binary')
        check_params_string(average: average)
        @average = average
      end

      # Calculate average recall
      #
      # @param y_true [Numo::Int32] (shape: [n_samples]) Ground truth labels.
      # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted labels.
      # @return [Float] Average recall
      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
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
rumale-0.13.8 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.7 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.6 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.5 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.4 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.3 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.2 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.1 lib/rumale/evaluation_measure/recall.rb
rumale-0.13.0 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.9 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.8 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.7 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.6 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.5 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.4 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.3 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.2 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.1 lib/rumale/evaluation_measure/recall.rb
rumale-0.12.0 lib/rumale/evaluation_measure/recall.rb
rumale-0.11.0 lib/rumale/evaluation_measure/recall.rb