Mean absolute error (MAE)#
Es una métrica de riesgo equivalente al valor esperado del error absoluto o norma L1.
Esta métrica no es sensitiva hacia los outliers.
Una desventaja de su uso como métrica en optimización es que el gradiente depende del signo del error y no de su magnitud.
Se computa como:
\text{MAE}(y, \hat{y}) = \frac{1}{n_{\text{samples}}} \sum_{i=0}^{n_{\text{samples}} - 1} |y_i - \hat{y}_i| = \frac{1}{n_{\text{samples}}} \sum_{i=0}^{n_{\text{samples}} - 1} |\hat{e}_i|
[1]:
from sklearn.metrics import mean_absolute_error
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
mean_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]]
mean_absolute_error(
y_true,
y_pred,
multioutput="raw_values",
)
[2]:
array([0.5, 1. ])
[3]:
mean_absolute_error(
y_true,
y_pred,
)
[3]:
0.75
[4]:
#
# 0.5 * 0.3 + 1.0 * 0.7 = 0.85
#
mean_absolute_error(
y_true,
y_pred,
multioutput=[0.3, 0.7],
)
[4]:
0.85