【问题标题】:auto.arima for daily data forecasts dates too much into the future用于每日数据预测的 auto.arima 日期太远了
【发布时间】:2020-07-12 11:41:19
【问题描述】:

我有访问者的每日数据,我正在尝试使用 auto.arima 进行预测。问题是数据集在 2017-09-10 结束,但第一次预测的日期是 2025 年。我希望模型预测未来 h 天,但它从错误的日期开始,只有 7预测一年而不是 365/366。这可能与 tsibble 数据结构及其对 arima 模型中日期的处理有关,但我不确定。

实际数据集较长,但我使用较短的数据集作为示例。

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)

【问题讨论】:

    标签: r forecasting arima tsibble


    【解决方案1】:

    您正在混合不应该放在一起的软件包。 forecast 包处理 ts 对象而不是 tsibble 对象。使用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)
    

    reprex package (v0.3.0) 于 2020-04-01 创建

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-30
      • 2017-07-31
      • 2021-05-02
      • 2017-11-14
      • 2016-07-23
      • 1970-01-01
      • 2020-03-07
      • 2021-12-10
      相关资源
      最近更新 更多