Median absolute error#
Es robusto a outliers.
Se computa como:
\text{MedAE}(y_i, \hat{y}_i) = \text{median}(|y_1 - \hat{y}_1|, \dots, |y_n - \hat{y}_n| = \text{median}(|\hat{e}_1|, \dots, |\hat{e}_n|)
[1]:
from sklearn.metrics import median_absolute_error
y_true = [3.0, -0.5, 2, 7]
y_pred = [2.5, +0.0, 2, 8]
# median(0.5, 0.5, 0.0, 1.0) = 0.5
median_absolute_error(
# -------------------------------------------------------------------------
# Ground truth (correct) target values.
y_true=y_true,
# -------------------------------------------------------------------------
# Estimated target values.
y_pred=y_pred,
# -------------------------------------------------------------------------
# Sample weights.
sample_weight=None,
# -------------------------------------------------------------------------
# Defines aggregating of multiple output scores.
# * 'raw_values': Returns a full set of scores in case of multioutput input.
# * 'uniform_average': Scores of all outputs are averaged with uniform
# weight.
multioutput="uniform_average",
)
[1]:
0.5
[2]:
y_true = [[0.5, 1], [-1, 1], [7, -6]]
y_pred = [[0.0, 2], [-1, 2], [8, -5]]
# median(0.5, 0.0, 1.0) = 0.5
# median(1.0, 1.0, 1.0) = 1.0
median_absolute_error(
y_true,
y_pred,
multioutput="raw_values",
)
[2]:
array([0.5, 1. ])
[3]:
#
# 0.5 * (0.5 + 1.0) = 0.75
#
median_absolute_error(
y_true,
y_pred,
)
[3]:
0.75
[4]:
#
# 0.3 * 0.5 + 0.7 * 1.0 = 0.85
#
median_absolute_error(
y_true,
y_pred,
multioutput=[0.3, 0.7],
)
[4]:
0.85