Method: Qoa::LossFunctions.mean_absolute_error

Defined in:
lib/qoa/loss_functions.rb

.mean_absolute_error(prediction, target) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
# File 'lib/qoa/loss_functions.rb', line 24

def mean_absolute_error(prediction, target)
  raise ArgumentError, 'prediction and target must have the same length' if prediction.size != target.size
  prediction.zip(target).map { |p, t| (p - t).abs }.sum / prediction.size
end