Sha256: 59b14310ecff4b9aabe46e436ae57adc6952508ce3678341251dec0a5fcf846b
Contents?: true
Size: 1.58 KB
Versions: 40
Compression:
Stored size: 1.58 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 # Precision is a class that calculates the preicision of the predicted labels. # # @example # evaluator = Rumale::EvaluationMeasure::Precision.new # puts evaluator.score(ground_truth, predicted) class Precision include Base::Evaluator include EvaluationMeasure::PrecisionRecall # Return the average type for calculation of precision. # @return [String] ('binary', 'micro', 'macro') attr_reader :average # Create a new evaluation measure calculater for precision score. # # @param average [String] The average type ('binary', 'micro', 'macro') def initialize(average: 'binary') check_params_string(average: average) @average = average end # Calculate average precision. # # @param y_true [Numo::Int32] (shape: [n_samples]) Ground truth labels. # @param y_pred [Numo::Int32] (shape: [n_samples]) Predicted labels. # @return [Float] Average precision def score(y_true, y_pred) y_true = check_convert_label_array(y_true) y_pred = check_convert_label_array(y_pred) case @average when 'binary' precision_each_class(y_true, y_pred).last when 'micro' micro_average_precision(y_true, y_pred) when 'macro' macro_average_precision(y_true, y_pred) end end end end end
Version data entries
40 entries across 40 versions & 1 rubygems