0

我正在尝试每天预测数据。如果我在 r 中使用 holtwinters 函数,我会收到警告消息并且无法执行输出

我使用了下面的代码

library(data.table)
library(forecast)
library(lubridate)

ruta = "D:\\datasets/"

dt_ts = fread(paste0(ruta,"Actuals.csv"))
dt_ts[,Dates:=as.Date(Dates,"%Y-%m-%d")]

# Removing 29 february
dt_ts = dt_ts[!Dates %in% as.Date("2016-02-29")]

regions = unique(dt_ts$Regions)
items = unique(dt_ts$Item)

ls_pred=list()
ls_model=list()
i<-regions[1]
j<-items[1]
for(i in regions){
  for(j in items){
    name_model = paste(i," - ",j)

    ts_temp = ts(dt_ts[Regions==i & Item==j,]$Data,frequency = 365,start = 
 c(2016,1,1))
    # plot(ts_temp)

    model_hw = HoltWinters(ts_temp)
    pred_hw = forecast(model_hw,h=365)
    # plot(pred_hw)

    pred_hw$mean = ifelse(pred_hw$mean<0,0,pred_hw$mean)
    # plot(pred_hw)

    ls_model[[name_model]] = model_hw
    ls_pred[[name_model]] = pred_hw$mean    


  }
}

我的数据如下

Regions Item    Dates   Data
Tiruchengode    TRACTOR TT35-4WD    01-01-16    2
Tiruchengode    TRACTOR TT35-4WD    02-01-16    7
Tiruchengode    TRACTOR TT35-4WD    03-01-16    6
Tiruchengode    TRACTOR TT35-4WD    04-01-16    0
Tiruchengode    TRACTOR TT35-4WD    05-01-16    6
Tiruchengode    TRACTOR TT35-4WD    06-01-16    6
Tiruchengode    TRACTOR TT35-4WD    07-01-16    1
Tiruchengode    TRACTOR TT35-4WD    08-01-16    6
Tiruchengode    TRACTOR TT35-4WD    09-01-16    0
Tiruchengode    TRACTOR TT35-4WD    10-01-16    4
Tiruchengode    TRACTOR TT35-4WD    11-01-16    4
Tiruchengode    TRACTOR TT35-4WD    12-01-16    0

我收到警告消息

任何建议请提前谢谢

4

0 回答 0