Skip to main content
deleted 1 character in body
Source Link
s__
  • 227
  • 3
  • 11

I'm learning now some metrics of goodness about time series forecasting, using the forecast package, but I'm stuck in something that surely I've not understood well. I have two vectors, of real data, and forecast data, and I'd like to calculate MAPE.

real <- c(1,2,3,0)
pred <- c(2,3,1,0) 
accuracy(real, pred,real)
         ME     RMSE MAE       MPE     MAPE
Test set  0 1.224745   1 -3827.8888977778 9472.4444422222

So I decided to try to calculate myself the MAPE, using the docs, so:

mean(abs((real-pred)/real*100))
[1] NaN

And clearly I got NaN, because I have a (0-0)/0.

My question is: am I calculating wrong manually the MAPE, or the function has a kind of na.rm = TRUE?

I'm learning now some metrics of goodness about time series forecasting, using the forecast package, but I'm stuck in something that surely I've not understood well. I have two vectors, of real data, and forecast data, and I'd like to calculate MAPE.

real <- c(1,2,3,0)
pred <- c(2,3,1,0) 
accuracy(real, pred)
         ME     RMSE MAE       MPE     MAPE
Test set  0 1.224745   1 -38.88889 94.44444

So I decided to try to calculate myself the MAPE, using the docs, so:

mean(abs((real-pred)/real*100))
[1] NaN

And clearly I got NaN, because I have a (0-0)/0.

My question is: am I calculating wrong manually the MAPE, or the function has a kind of na.rm = TRUE?

I'm learning now some metrics of goodness about time series forecasting, using the forecast package, but I'm stuck in something that surely I've not understood well. I have two vectors, of real data, and forecast data, and I'd like to calculate MAPE.

real <- c(1,2,3,0)
pred <- c(2,3,1,0) 
accuracy(pred,real)
         ME     RMSE MAE       MPE     MAPE
Test set  0 1.224745   1 -27.77778 72.22222

So I decided to try to calculate myself the MAPE, using the docs, so:

mean(abs((real-pred)/real*100))
[1] NaN

And clearly I got NaN, because I have a (0-0)/0.

My question is: am I calculating wrong manually the MAPE, or the function has a kind of na.rm = TRUE?

Source Link
s__
  • 227
  • 3
  • 11

Why forecast::accuracy() mape is working with 0/0?

I'm learning now some metrics of goodness about time series forecasting, using the forecast package, but I'm stuck in something that surely I've not understood well. I have two vectors, of real data, and forecast data, and I'd like to calculate MAPE.

real <- c(1,2,3,0)
pred <- c(2,3,1,0) 
accuracy(real, pred)
         ME     RMSE MAE       MPE     MAPE
Test set  0 1.224745   1 -38.88889 94.44444

So I decided to try to calculate myself the MAPE, using the docs, so:

mean(abs((real-pred)/real*100))
[1] NaN

And clearly I got NaN, because I have a (0-0)/0.

My question is: am I calculating wrong manually the MAPE, or the function has a kind of na.rm = TRUE?