寓言中的预测功能是否提供一步预测?

Does the forecast function within fable provide one-step forecasts?

here, making one-step forecasts in the test set is a way of avoiding the inevitable increase in variance as a forecast horizon increases. Mentioned in that section are methods to perform one-step forecasts on the test set using an already-trained model, for the forecast package. Is there a similar way of performing a one-step forecast for test data using the newer fable package? Perhaps the new_data parameter described here, for example 所述处理此问题,但我不确定,因为 h = 24new_data = x_test 的预测在下面相同:

> library(fable)
> library(fabletools)
> x <- USAccDeaths %>%
+   as_tsibble()
> x
# A tsibble: 72 x 2 [1M]
      index value
      <mth> <dbl>
 1 1973 Jan  9007
 2 1973 Feb  8106
 3 1973 Mar  8928
 4 1973 Apr  9137
 5 1973 May 10017
 6 1973 Jun 10826
 7 1973 Jul 11317
 8 1973 Aug 10744
 9 1973 Sep  9713
10 1973 Oct  9938
# … with 62 more rows
> x_train <- x %>% filter(year(index) < 1977)
> x_test <- x %>% filter(year(index) >= 1977)
> fit <- x_train %>% model(arima = ARIMA(log(value) ~ pdq(0, 1, 1) + PDQ(0, 1, 1)))
> fit
# A mable: 1 x 1
                      arima
                    <model>
1 <ARIMA(0,1,1)(0,1,1)[12]>
> nrow(x_test)
[1] 24
> forecast(fit, h = 24)$.mean
 [1]  7778.052  7268.527  7831.507  7916.845  8769.478  9144.790 10004.816  9326.874  8172.226
[10]  8527.355  8015.100  8378.166  7692.356  7191.343  7751.466  7839.085  8686.833  9062.247
[19]  9918.487  9250.101  8108.202  8463.933  7958.667  8322.497
> forecast(fit, new_data = x_test)$.mean
 [1]  7778.052  7268.527  7831.507  7916.845  8769.478  9144.790 10004.816  9326.874  8172.226
[10]  8527.355  8015.100  8378.166  7692.356  7191.343  7751.466  7839.085  8686.833  9062.247
[19]  9918.487  9250.101  8108.202  8463.933  7958.667  8322.497

答案和代码

{forecast} 包中的许多模型可用的 model 参数等同于 {fable} 包中的 refit() 方法。当与未来数据一起使用时,它可用于从一个模型中生成多个 one-step 预测。

library(forecast)
fit <- head(USAccDeaths, -24) %>% 
  auto.arima()
fit_test <- tail(USAccDeaths, 24) %>% 
  Arima(model = fit)
accuracy(fit_test)
#>                    ME     RMSE      MAE       MPE      MAPE      MASE
#> Training set 22.45098 167.0648 85.59724 0.2382773 0.9327587 0.3298545
#>                    ACF1
#> Training set -0.0968173

library(fable)
library(dplyr)
us_accidental_deaths <- as_tsibble(USAccDeaths)
fit <- head(us_accidental_deaths, -24) %>% 
  model(ARIMA(value))
fit_test <- refit(fit, tail(us_accidental_deaths, 24), reestimate = FALSE)
accuracy(fit_test)
#> # A tibble: 1 x 10
#>   .model       .type       ME  RMSE   MAE   MPE  MAPE  MASE RMSSE    ACF1
#>   <chr>        <chr>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>
#> 1 ARIMA(value) Training  22.5  167.  85.6 0.238 0.933 0.330 0.490 -0.0968

reprex package (v0.3.0)

于 2020-10-13 创建

说明

模型的 fitted() 值是 one-step 提前预测,可用于评估 'training accuracy' 性能(对训练数据的预测准确性)。但是有一个问题 - 模型的估计参数是基于整个训练集的,因此训练精度比预期的要好(模型包含一些关于它所拟合的未来的信息)。

forecast()函数用于生成模型从未见过的未来时间点的预测。您可以使用 forecast(<mable>, h = 1) 生成单个 one-step 提前预测。然而,这只会产生一个单一的预测。相反,我们想要生成一个 one-step 提前预测,向模型添加一个新的观察结果,然后在该新观察结果之外生成另一个 one-step 提前预测(重复直到 运行 没有数据) .

这就是refit()函数有用的地方。它采用现有模型,并将其应用于新数据集。此改装过程涉及计算 one-step 数据预测(fitted() 值)。通过设置 reestimate = FALSE,模型的估计系数将不会更新以更好地适应新的 'future' 数据。这解决了模型系数的问题,其中包含一些关于我们正在测试预测准确性的未来值的信息。