Class: Rumale::EvaluationMeasure::MedianAbsoluteError

Inherits:
Object
  • Object
show all
Includes:
Base::Evaluator
Defined in:
lib/rumale/evaluation_measure/median_absolute_error.rb

Overview

MedianAbsoluteError is a class that calculates the median absolute error.

Examples:

evaluator = Rumale::EvaluationMeasure::MedianAbsoluteError.new
puts evaluator.score(ground_truth, predicted)

Instance Method Summary collapse

Instance Method Details

#score(y_true, y_pred) ⇒ Float

Calculate median absolute error.

Parameters:

  • y_true (Numo::DFloat)

    (shape: [n_samples]) Ground truth target values.

  • y_pred (Numo::DFloat)

    (shape: [n_samples]) Estimated target values.

Returns:

  • (Float)

    Median absolute error.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
# File 'lib/rumale/evaluation_measure/median_absolute_error.rb', line 20

def score(y_true, y_pred)
  check_tvalue_array(y_true)
  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
  raise ArgumentError, 'Expect target values to be 1-D arrray' if [y_true.shape.size, y_pred.shape.size].max > 1

  (y_true - y_pred).abs.median
end