【问题标题】:Cross validation of monthly time series using fable package使用 fable 包交叉验证每月时间序列
【发布时间】:2021-02-27 23:01:11
【问题描述】:

我有一个每月的时间序列数据,我想使用 Fable 包中的不同模型对其进行建模,方法是使用交叉验证来了解所考虑模型中的最佳模型。

# My data
google <-  read_csv("google.csv") %>% 
  tsibble(index = date)

# dimension of the data is 60 by 2.

]1

# Training data for cross validation

google_tr <- google %>%
  slice(1:(n()-1)) %>%
  stretch_tsibble(.init = 3, .step = 1)

# Building models for the data
fc <- google_tr %>% 
  model(ets = ETS(closing_price),
        arima =   ARIMA(closing_price),
        rw = RW(closing_price ~ drift()),
        prophet = prophet(closing_price)) %>% 
  forecast(h = "1 year")

出现了很多警告!

模型评估

fc %>% accuracy(google)

我已经阅读了https://otexts.com/fpp3/tscv.htmlhttps://otexts.com/fpp3/arima-ets.html#example-comparing-arima-and-ets-on-non-seasonal-data 没有数字的时间,但我仍然不知道如何选择正确的训练数据。如果我能在下面的块中为slice()stretch_tsibble() 获得正确的每月数据输入,那么问题将得到解决。

google_tr <- google %>%
  slice(1:(n()-1)) %>%
  stretch_tsibble(.init = 3, .step = 1)

【问题讨论】:

    标签: r time-series cross-validation fable-r


    【解决方案1】:

    我不能评论那个特定的数据集,因为你没有分享它,甚至说已经加载了哪些包。但是可以提出几点:

    1. 您的初始切片是 3 个观察值。您无法拟合具有 3 个观测值的 ETS 或 ARIMA 模型,因此您会收到警告。其他小切片也会出现警告。我建议您从每月数据集的至少十几个观察值开始。
    2. 最后的警告是因为您有不完整的样本外数据 - 也就是说,您正在预测提前 1 年,并且您的一些切片涉及的数据包括最后一年的观察结果。因此,当实际值未知时,您无法将预测值与实际值进行比较。

    这是一个使用月度数据的示例。

    library(fpp3)
    
    test <- USAccDeaths %>% as_tsibble()
    
    test_tr <- test %>%
      slice(1:(n()-1)) %>%
      stretch_tsibble(.init = 12, .step = 1)
    
    fc <- test_tr %>%
      model(ets = ETS(value),
            arima =   ARIMA(value),
            rw = RW(value ~ drift()),
            ) %>%
      forecast(h = "1 year")
    
    fc %>% accuracy(test)
    

    【讨论】:

    • 非常感谢@RobHyndman。当我尝试以下代码时,我仍然有一些警告。请问到底是什么原因造成的?
    猜你喜欢
    • 2018-10-10
    • 1970-01-01
    • 2016-12-06
    • 2020-05-30
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多