简体   繁体   English

用于每日数据预测的 auto.arima 日期太远

[英]auto.arima for daily data forecasts dates too much into the future

I have daily data of visitors, which I'm trying to forecast using auto.arima.我有访问者的每日数据,我正在尝试使用 auto.arima 进行预测。 The problem is that the dataset ends in 2017-09-10, but the date for the first forecast is in 2025. I would like the model to make forecasts h days into the future, but it starts at the wrong date and makes just 7 forecasts a year instead of 365/366.问题是数据集结束于 2017 年 9 月 10 日,但第一次预测的日期是 2025 年。我希望模型对未来 h 天进行预测,但它从错误的日期开始,只进行了 7预测一年而不是 365/366。 This probably has something to do with the tsibble data structure and its handling of dates into the arima model but I'm not sure.这可能与 tsibble 数据结构及其将日期处理到 arima 模型中有关,但我不确定。

The actual dataset is longer but I'm using the shorter one just as an example.实际数据集更长,但我使用较短的数据集仅作为示例。

library(forecast)
library(tsibble)

data <- structure(list(dates = structure(c(17366, 17367, 17368, 17369, 
17370, 17371, 17372, 17373, 17374, 17375, 17376, 17377, 17378, 
17379, 17380, 17381, 17382, 17383, 17384, 17385, 17386, 17387, 
17388, 17389, 17390, 17391, 17392, 17393, 17394, 17395, 17396, 
17397, 17398, 17399, 17400, 17401, 17402, 17403, 17404, 17405, 
17406, 17407, 17408, 17409, 17410, 17411, 17412, 17413, 17414, 
17415, 17416, 17417, 17418, 17419), class = "Date"), amount = c(140259004L, 
137461014L, 133577835L, 140119981L, 150459411L, 150351610L, 146260160L, 
140679789L, 137475996L, 132494397L, 136308902L, 147320206L, 150067135L, 
140510359L, 139777366L, 136165099L, 131913565L, 131895017L, 143034246L, 
149088594L, 146601589L, 146642062L, 143600939L, 135980097L, 141922119L, 
148676920L, 152191991L, 157564268L, 153750311L, 147384628L, 138167523L, 
136748018L, 147513392L, 152316844L, 146654846L, 147868709L, 140309766L, 
137225882L, 139028747L, 155939179L, 160846148L, 153346249L, 147921236L, 
148184826L, 146683058L, 144881045L, 166062400L, 166791506L, 162190588L, 
172354146L, 180731284L, 136754670L, 132359512L, 141863949L)), row.names = c(NA, 
-54L), class = "data.frame")

data <- as_tsibble(data)

tail(data$dates)

auto.arima(data) %>% forecast(10)

You are mixing packages that should not go together.您正在混合不应放在一起的软件包。 The forecast package handles ts objects not tsibble objects. forecast包处理ts对象而不是tsibble对象。 Replace the forecast package with the fable package when using tsibble objects.使用tsibble对象时,将预测包替换为寓言包。

library(tsibble)
library(fable)

data <- tsibble(
  dates = structure(c(
    17366, 17367, 17368, 17369, 17370, 17371, 17372, 17373, 17374,
    17375, 17376, 17377, 17378, 17379, 17380, 17381, 17382, 17383,
    17384, 17385, 17386, 17387, 17388, 17389, 17390, 17391, 17392,
    17393, 17394, 17395, 17396, 17397, 17398, 17399, 17400, 17401,
    17402, 17403, 17404, 17405, 17406, 17407, 17408, 17409, 17410,
    17411, 17412, 17413, 17414, 17415, 17416, 17417, 17418, 17419
  ), class = "Date"),
  amount = c(
    140259004L,
    137461014L, 133577835L, 140119981L, 150459411L, 150351610L, 146260160L,
    140679789L, 137475996L, 132494397L, 136308902L, 147320206L, 150067135L,
    140510359L, 139777366L, 136165099L, 131913565L, 131895017L, 143034246L,
    149088594L, 146601589L, 146642062L, 143600939L, 135980097L, 141922119L,
    148676920L, 152191991L, 157564268L, 153750311L, 147384628L, 138167523L,
    136748018L, 147513392L, 152316844L, 146654846L, 147868709L, 140309766L,
    137225882L, 139028747L, 155939179L, 160846148L, 153346249L, 147921236L,
    148184826L, 146683058L, 144881045L, 166062400L, 166791506L, 162190588L,
    172354146L, 180731284L, 136754670L, 132359512L, 141863949L
  ),
  index = dates
)

data %>%
  model(
    arima = ARIMA(amount)
  ) %>%
  forecast(h = 10)
#> # A fable: 10 x 4 [1D]
#> # Key:     .model [1]
#>    .model dates          amount .distribution      
#>    <chr>  <date>          <dbl> <dist>             
#>  1 arima  2017-09-11 156148449. N(1.6e+08, 4.6e+13)
#>  2 arima  2017-09-12 156677612. N(1.6e+08, 6.5e+13)
#>  3 arima  2017-09-13 160812213. N(1.6e+08, 6.8e+13)
#>  4 arima  2017-09-14 160909814. N(1.6e+08, 6.8e+13)
#>  5 arima  2017-09-15 144449326. N(1.4e+08, 6.8e+13)
#>  6 arima  2017-09-16 143739717. N(1.4e+08, 6.8e+13)
#>  7 arima  2017-09-17 156979719. N(1.6e+08, 6.8e+13)
#>  8 arima  2017-09-18 163510495. N(1.6e+08, 7.3e+13)
#>  9 arima  2017-09-19 160618600. N(1.6e+08, 7.4e+13)
#> 10 arima  2017-09-20 162818145. N(1.6e+08, 7.5e+13)

Created on 2020-04-01 by the reprex package (v0.3.0)reprex 包(v0.3.0) 于 2020 年 4 月 1 日创建

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM