确定R中的最佳预测模型并比较MAPE

时间:2018-10-26 02:23:11

标签: r forecasting best-fit

我有100多种产品可以使用R中的至少3种统计模型来预测预测。 对于数据集中的每个产品,我将使用所有三个模型进行预测,然后基于MAPE为该产品选择最佳模型。因此,最后,我的每个产品的输出应在单个列中包含实际和预测,而我的100个产品将根据其趋势和季节性使用不同的模型。 这是我的脚本,有人可以找到上述解决方案

library(reshape2)
library(forecast)
# one column for date and differents product/sales in other columns
result_0 = read.csv("Test.csv")
#Dividing testing & training
result <- result_0[1:(nrow(result_0)*(4/5)), ] 
#testing set
#result_tes <- result_0[32:nrow(result_0), ]
result_tes <- result_0[(nrow(result_0)*(4/5)):nrow(result_0), ]
#nrow(result_tes)
Data_ts <- ts(result[,],f=7)
#h <- 50
h <- nrow(result_tes)+360
ns <- ncol(Data_ts)
#Triple Exponential
triplefc <- matrix(NA, nrow=h, ncol=ns)
for (i in 2:ns){
  triplefc[,i] <- hw((Data_ts[,i]), h=h)$mean}
#ARIMA
arimaforecast <- matrix(NA, nrow=h, ncol=ns)
for (i in 2:ns){
  arimaforecast[,i] <- forecast(auto.arima(Data_ts[,i]), h=h)$mean}

0 个答案:

没有答案