Class: Rumale::EvaluationMeasure::MeanSquaredLogError

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

Overview

MeanSquaredLogError is a class that calculates the mean squared logarithmic error.

Examples:

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

Instance Method Summary collapse

Instance Method Details

#score(y_true, y_pred) ⇒ Float

Calculate mean squared logarithmic error.

Parameters:

  • y_true (Numo::DFloat)

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

  • y_pred (Numo::DFloat)

    (shape: [n_samples, n_outputs]) Estimated target values.

Returns:

  • (Float)

    Mean squared logarithmic error.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File 'lib/rumale/evaluation_measure/mean_squared_log_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

  ((Numo::NMath.log(y_true + 1) - Numo::NMath.log(y_pred + 1))**2).mean
end