mean_absolute_error

Function mean_absolute_error 

Source
pub fn mean_absolute_error<F, S1, S2, D1, D2>(
    y_true: &ArrayBase<S1, D1>,
    y_pred: &ArrayBase<S2, D2>,
) -> Result<F>
where F: Float + NumCast + Debug + SimdUnifiedOps, S1: Data<Elem = F>, S2: Data<Elem = F>, D1: Dimension, D2: Dimension,
Expand description

Calculates the mean absolute error (MAE)

Mean absolute error measures the average absolute difference between the estimated values and the actual value.

§Arguments

  • y_true - Ground truth (correct) target values
  • y_pred - Estimated target values

§Returns

  • The mean absolute error

§Examples

use scirs2_core::ndarray::array;
use scirs2_metrics::regression::mean_absolute_error;

let y_true = array![3.0, -0.5, 2.0, 7.0];
let y_pred = array![2.5, 0.0, 2.0, 8.0];

let mae: f64 = mean_absolute_error(&y_true, &y_pred).unwrap();
// Expecting: (|3.0-2.5| + |-0.5-0.0| + |2.0-2.0| + |7.0-8.0|) / 4 = 0.5
assert!(mae > 0.499 && mae < 0.501);