This function computes the absolute percentage error.
Usage
absolute_percentage_error(
true,
pred,
weights = NULL,
rweights = NULL,
multi = c("average", "sum", "raw"),
eps = 1e-10
)
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
- 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 percentage 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 percentage error (APE) is based on absolute values. The absolute percentage error is defined as
$$APE(y,\hat{y}) = \frac{\lvert y_{i} - \hat{y}_{i} \rvert}{\max{\lvert y_{i} \rvert, \epsilon}}$$
where \(y_{i}\) is the true value of the \(i\)-th sample, \(\hat{y}_{i}\) is the predicted value, and \(\epsilon\) is an arbitrary positive small number used to avoid a division by zero.
If response has multiple output values and weights are provided, then the error is weighted.
$$wAPE(w,y,\hat{y}) = \frac{w * \lvert y_{i} - \hat{y}_{i} \rvert}{\max{\lvert y_{i} \rvert, \epsilon}}$$
where \(w\) is a vector of \(n\) elements, \(w_{j}\) is the weighting factor assigned to the \(j\)-th response. The best possible score is zero.