weighted_median_absolute_error

Function weighted_median_absolute_error 

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

Calculates the weighted median absolute error

This function applies weights to each sample’s absolute error and returns the weighted median, which is more robust to outliers than mean-based metrics.

§Arguments

  • y_true - Ground truth (correct) target values
  • y_pred - Estimated target values
  • weights - Sample weights (same length as y_true/y_pred)

§Returns

  • The weighted median absolute error

§Examples

use scirs2_core::ndarray::array;
use scirs2_metrics::regression::weighted_median_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 weights = array![1.0, 0.5, 1.0, 0.2]; // Less weight on outliers

let wmedae = weighted_median_absolute_error(&y_true, &y_pred, &weights).unwrap();
assert!(wmedae >= 0.0);