Sha256: d96b01edb0a12f13c3e1a60993b844c1a3f4b0c52bfc0236d9484d4f76a937a2
Contents?: true
Size: 1.4 KB
Versions: 2
Compression:
Stored size: 1.4 KB
Contents
require 'svmkit/base/evaluator' require 'svmkit/evaluation_measure/precision_recall' module SVMKit # 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 = SVMKit::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') @average = average end # Claculate 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) 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
svmkit-0.2.5 | lib/svmkit/evaluation_measure/precision.rb |
svmkit-0.2.4 | lib/svmkit/evaluation_measure/precision.rb |