在MAPE的基础上应用不同的时间序列模型(ARIMA,HOLT-WINTER)

时间:2016-07-09 13:20:09

标签: r time-series forecasting holtwinters

我有一个时间序列对象calc_visit_ts我想基于每个模型的MAPE值应用最佳拟合时间序列模型。我面临的问题是MAPE值HOLT-WINTER乘法模型无法以与其他模型相同的方式计算模型(因为它与summary(visit_model_Hw_M)比较时给出了不同的MAPE值。)

#### AUTO-ARIMA
visit_model_Arima <- auto.arima(calc_visit_ts)
# summary(visit_model_Arima)

#### HOLT-WINTER ADDITIVE
visit_model_Hw_A <- hw(calc_visit_ts,h=monthly_prediction,seasonal = "additive")
# summary(visit_model_Hw_A)

#### HOLT-WINTER MULTIPLICATIVE
visit_model_Hw_M <- hw(calc_visit_ts,h=monthly_prediction,seasonal = "multiplicative")
# summary(visit_model_Hw_M)


#### Calculating MAPE on models for best suit
model_Mape<- c( MAPE_model(visit_model_Arima)
                ,MAPE_model(visit_model_Hw_A))
                #,MAPE_model(visit_model_Hw_M))  this is not accurate

model_Mape=na.omit(model_Mape)
token<-which(min(model_Mape)==model_Mape)

if(length(token)>0)
{
  if(token==1)
    {visit_model<-visit_model_Arima
  }else if(token==2)
    {visit_model<-visit_model_Hw_A
  }else if(token==3)
    {visit_model<-visit_model_Hw_M
  }else 
  {
    ##EXCEPTION HANDLING  
  }
}

summary(visit_model)

以下是模型上用于执行MAPE计算的函数 -

MAPE_model <- function(visit_model) {
 #CHECK FOR ZERO CONDIITION  if(visit_model$x!=0)
 mape = mean(abs(visit_model$residuals)/visit_model$x)
 return(mape)
}
时间序列

数据 -

calc_visit_ts
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2012          35  53  65  60  64  49  63  55  59  66
2013  62  54  77  67  84  62  82  65  59  67  60  67
2014  73  75  55  76  93  96  89  76  88  65  83  82
2015  76  72  75  94  91  83  72  73  80  83  81  81
2016  97  91  90  80 101  98  

dput(calc_visit_ts)
structure(c(35, 53, 65, 60, 64, 49, 63, 55, 59, 66, 62, 54, 77, 
67, 84, 62, 82, 65, 59, 67, 60, 67, 73, 75, 55, 76, 93, 96, 89, 
76, 88, 65, 83, 82, 76, 72, 75, 94, 91, 83, 72, 73, 80, 83, 81, 
81, 97, 91, 90, 80, 101, 98), .Tsp = c(2012.16666666667, 2016.41666666667, 
12), class = "ts")

准确显示我的意思 -

Holt-Winter Additive Plot

Holt-Winter Additive Plot

Holt-Winter Multiplicative Plot Holt-Winter Multiplicative Plot

问题 summary(visit_model_Hw_M)MAPE = 9.075097 然而,MAPE_model(visit_model_Hw_M)给出了0.001273087,因为乘法模型适合曲线(数据点),因此使用visit_model_Hw_M$residuals并不是计算MAPE的合适方法(因为函数试图拟合)曲线)。

有没有办法可以从摘要本身获取HOLT-WINTER乘法的MAPE值?或者正确估算HOLT-WINTER乘法模型的MAPE值的方法?

1 个答案:

答案 0 :(得分:0)

经过对数据和反复试验的深思熟虑,我发现ARIMAHolt-Winter模型的MAPE计算方式不同 -

MAPE_model <- function(visit_model,model_type) {
 if(model_type == "ARIMA")
  mape = mean(abs(visit_model$residuals)/visit_model$x)
 if(model_type == "HW")
  mape = mean(abs(visit_model$x - visit_model$fitted)/visit_model$x)
 else
  mape = -1  #Something
 return(mape)
}

虽然符号visit_model$x - visit_model$fitted在规范上等同于visit_model$residualsARIMA中的Holt-Winter(additive),但Holt-Winter(multiplicative)模型中并非如此。因此,区别为model_type