从 fabletools 包中的准确度函数获取空结果 [英] Getting null results from the accuracy function in fabletools package

查看:16
本文介绍了从 fabletools 包中的准确度函数获取空结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的时间序列t值1 122 123 04 05 06 07 0我希望 acf1 等于 0.443,但准确度函数产生空值.代码如下:

I have a time series that looks like this t value 1 12 2 12 3 0 4 0 5 0 6 0 7 0 I expect acf1 to equal 0.443, but instead the accuracy function produces null. The code is as following:

df = data.frame("t" = 1:7, "value" = c(12, 12, 0, 0, 0, 0, 0))
tsb = df %>%
as_tsibble(index = t)
md = tsb %>% model(arima = ARIMA(value ~ PDQ(period = 4), stepwise = F))

fc = md %>% forecast(h = 4)

accuracy(fc, tsb)

为什么会这样?

推荐答案

accuracy() 中的 ACF1 列是残差的第一个自相关.您期望的 0.443 的 ACF1 是您的数据的第一个自相关,可以通过以下方式获得:

The ACF1 column from accuracy() is the first auto-correlation of the residuals. The ACF1 of 0.443 that you expect is the first auto-correlation of your data, which can be obtained with:

library(feasts)
#> Loading required package: fabletools
df = data.frame("t" = 1:7, "value" = c(12, 12, 0, 0, 0, 0, 0))
tsb = df %>%
  as_tsibble(index = t)
tsb %>% ACF(lag_max = 1)
#> Response variable not specified, automatically selected `var = value`
#> # A tsibble: 1 x 2 [1]
#>     lag   acf
#>   <lag> <dbl>
#> 1     1 0.443

reprex 包 (v0.3.0) 于 2020 年 8 月 13 日创建

Created on 2020-08-13 by the reprex package (v0.3.0)

您使用的第二个问题是预测的 accuracy() 需要未来的数据来计算预测误差.fc 中的预测与 tsb 提供的时间不匹配,因此无法计算预测误差.

The second problem with your usage is that accuracy() for forecasts requires future data to compute the forecast errors. The forecasts in fc do not match the times provided by tsb, and so no forecast errors can be computed.

library(tsibble)
library(dplyr)
library(fable)

md = tsb %>% model(arima = ARIMA(value ~ PDQ(period = 4), stepwise = F))
fc = md %>% forecast(h = 4)

# Make up some future data for evaluating forecast accuracy
tsb_future <- new_data(tsb, 4) %>% mutate(value = rnorm(4))
# Compute the accuracy of the forecasts against the tsb_future scenario
accuracy(fc, tsb_future)
#> # A tibble: 1 x 9
#>   .model .type     ME  RMSE   MAE   MPE  MAPE  MASE    ACF1
#>   <chr>  <chr>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>   <dbl>
#> 1 arima  Test  -0.779  1.09 0.975   100   100   NaN -0.0478

reprex 包 (v0.3.0) 于 2020 年 8 月 13 日创建

Created on 2020-08-13 by the reprex package (v0.3.0)

这篇关于从 fabletools 包中的准确度函数获取空结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆