This function computes the mean absolute error.
Usage
mean_absolute_error(
true,
pred,
weights = NULL,
multi = c("average", "sum", "raw"),
rweights = NULL
)
Arguments
- true
a vector (or a matrix) of observed values. If a matrix is provided, a multi-response is assumed
- pred
a vector (or a matrix) of predicted values
- weights
observation weights
- multi
what to do when response has multiple output values
average
errors of multiple outputs are averaged to get a single value for each observation
sum
errors of multiple outputs are summed up to get a single value for each observation
raw
returns a vector containing one error for each output
- rweights
response weights
Value
the mean absolute error, a positive double
or a vector of positive double
values,
one for each response, if response has multiple output values and multi = "raw"
Details
The mean absolute error (MAE) is a measure of errors based on absolute values. It treats small and large errors equally so it is less sensitive to outliers compared to other measures (e.g. MSE). The MAE estimated over n observations is defined as
$$MAE(y,\hat{y}) = \frac{1}{n}\sum_{i=1}^{n} \lvert y_{i} - \hat{y}_{i} \rvert$$
where \(y_{i}\) is the true value of the \(i\)-th sample and \(\hat{y}_{i}\) is the predicted value. If observation weights are provided, then the weighted mean absolute error is computed as
$$wMAE(w,y,\hat{y}) = \frac{1}{\sum_{i=1}^{n} w_{i}}\sum_{i=1}^{n} w_{i} * \lvert y_{i} - \hat{y}_{i} \rvert$$
where \(w_{i}\) is the weighting factor assigned to the \(i\)-th observation. The best possible score is zero.