我正在使用 fable 包来预测分层时间序列,并且所有节点的深度不相等。用例是在国家 -> 州 -> 地区级别预测联系人。汇总时,预测值必须与国家/地区级别相加(较低级别的预测等同于较高级别的预测。)
https://robjhyndman.com/papers/Foresight-hts-final.pdf
下面是我在预测时尝试的代码关于测试数据。
library(fable)
library(tsibble)
library(tsibbledata)
library(lubridate)
library(dplyr)
# selecting train data
train_df <- tourism %>%
filter(year(Quarter) <= 2014 & Region %in% c("MacDonnell", "Melbourne"))
# selecting test data
test_df <- tourism %>%
filter(year(Quarter) > 2014 & Region %in% c("MacDonnell", "Melbourne"))
# fitting ets model with reconcilliation
ets_fit <- train_df %>%
aggregate_key(Purpose * (State / Region), Trips = sum(Trips)) %>%
model(ets=ETS(Trips)) %>%
reconcile(ets_adjusted = min_trace(ets))
# forecasting on test data
fcasts_test <- forecast(ets_fit, test_df)
得到错误为
Error: Provided data contains a different key structure to the models.
Run `rlang::last_error()` to see where the error occurred.
我该如何解决这个问题?