Skip to contents

This function computes the absolute error.

Usage

absolute_error(
  true,
  pred,
  weights = NULL,
  rweights = NULL,
  multi = c("average", "sum", "raw")
)

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. This argument is for consistency, but not currently used.

rweights

response 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

Value

the absolute error, a vector of positive double values or a matrix, having one column for each response, if response has multiple output values and multi = "raw"

Details

The absolute error (AE) is based on absolute values and it is defined as

$$AE(y_{i},\hat{y}_{i}) = \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 the observed data has multiple output values and weights are provided, then the error is weighted.

$$wAE(w,y,\hat{y}) = \frac{1}{\sum_{j=1}^{n} w_{j}} w * \lvert y_{i} - \hat{y}_{i} \rvert$$

where \(w_{j}\) is the weighting factor assigned to the \(j\)-th response. The best possible score is zero.

Author

Alessandro Barberis