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

Version Path
svmkit-0.7.3 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.7.2 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.7.1 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.7.0 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.6.3 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.6.2 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.6.1 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.6.0 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.5.2 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.5.1 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.5.0 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.4.1 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.4.0 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.3.3 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.3.2 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.3.1 lib/svmkit/evaluation_measure/mean_squared_error.rb
svmkit-0.3.0 lib/svmkit/evaluation_measure/mean_squared_error.rb