Sha256: 9e3a02a1da8460da1c776e08c9e82ca468596dad5a842fb55abac352c054eaf0
Contents?: true
Size: 1013 Bytes
Versions: 17
Compression:
Stored size: 1013 Bytes
Contents
# frozen_string_literal: true require 'svmkit/validation' require 'svmkit/base/evaluator' module SVMKit module EvaluationMeasure # MeanSquaredError is a class that calculates the mean squared error. # # @example # evaluator = SVMKit::EvaluationMeasure::MeanSquaredError.new # puts evaluator.score(ground_truth, predicted) class MeanSquaredError include Base::Evaluator # Calculate mean squared error. # # @param y_true [Numo::DFloat] (shape: [n_samples, n_outputs]) Ground truth target values. # @param y_pred [Numo::DFloat] (shape: [n_samples, n_outputs]) Estimated target values. # @return [Float] Mean squared error def score(y_true, y_pred) SVMKit::Validation.check_tvalue_array(y_true) SVMKit::Validation.check_tvalue_array(y_pred) raise ArgumentError, 'Expect to have the same size both y_true and y_pred.' unless y_true.shape == y_pred.shape ((y_true - y_pred)**2).mean end end end end
Version data entries
17 entries across 17 versions & 1 rubygems