Reputation: 53
Hy guys, after a process of forecasting of time series, I've obtained a data frame (df) that is like this (numbers are only examples):
fcast_mean | actual_values
12,5 | 12,3
1,1 | 0
24,3 | 22,7
29,6 | 30,4
... | ...
I know that MAPE is infinite if actual_value is zero and this is my situation!
My question is: Is it mathematically wrong to put 0 instead of Inf in the row (in this case the 2nd row) where abs(actual_values - fcast$mean)/abs(actual_values)
is equal to Inf
?
What are the consequences of this change for the calculation of MAPE?
It becomes no longer a reliable indicator for the accuracy of forecasting?
My part of R code for the MAPE is:
x <- abs(df$actual_values-df$fcast_mean)/abs(df$actual_values)
x[is.infinite(x)] <- 0
MAPE <- (1/nrow(df$actual_values))*(sum(x))*100
Upvotes: 5
Views: 15488
Reputation: 31810
You cannot just change Inf
to 0 and expect the results to make any sense. An infinite MAPE is one of the problems that can arise with MAPEs. Use alternative measures of accuracy when this problem arises.
MASE is one alternative (mean absolute scaled error), described here.
Since you are using R, the accuracy
function from the forecast
package might be useful.
Upvotes: 8