m_estimator

Function m_estimator 

Source
pub fn m_estimator<F, S1, S2, D1, D2>(
    y_true: &ArrayBase<S1, D1>,
    y_pred: &ArrayBase<S2, D2>,
    loss_function: &str,
    tuning: Option<F>,
) -> Result<F>
where F: Float + NumCast + Debug + FromPrimitive, S1: Data<Elem = F>, S2: Data<Elem = F>, D1: Dimension, D2: Dimension,
Expand description

Calculates the M-estimator for regression

M-estimators are robust regression estimators that downweight the influence of outliers.

§Arguments

  • y_true - Ground truth (correct) target values
  • y_pred - Estimated target values
  • loss_function - Loss function to use:
    • “huber” - Huber loss (quadratic for small errors, linear for large errors)
    • “bisquare” - Tukey’s bisquare loss (bounded influence function)
    • “cauchy” - Cauchy loss (smoother than Huber)
  • tuning - Optional tuning parameter for the loss function

§Returns

  • The M-estimator value

§Examples

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

let y_true = array![3.0, -0.5, 2.0, 7.0, 10.0]; // 10.0 is an outlier
let y_pred = array![2.5, 0.0, 2.0, 8.0, 5.0];

// Standard MSE is heavily influenced by the outlier
// Let's use a robust M-estimator instead
let m_est = m_estimator(&y_true, &y_pred, "huber", None).unwrap();
assert!(m_est >= 0.0);