tidyverts / fabletools

General fable features useful for extension packages
http://fabletools.tidyverts.org/
89 stars 31 forks source link

Forecasting bug when using lagged predictor and multiple training sets #326

Open Timood opened 2 years ago

Timood commented 2 years ago

Hi all,

I am trying to do cross-validation on a model with lagged predictors. I had some unexpected forecasting results. Below, you'll find an example.

library(fpp3)

insurance_train <- insurance %>%
  stretch_tsibble(.init = 39, .step = 1, .id=".id")

# Commenting out this rule leads to a different forecast for May 2005
# insurance_train <- filter(insurance_train, .id == 2)

fit <- insurance_train %>%
  model(
    lag = ARIMA(Quotes ~ pdq(d = 0) + lag(TVadverts))
  )

insurance_test <- new_data(insurance_train, 1) %>%
  left_join(select(insurance, TVadverts), by='Month')

fit %>%
  forecast(insurance_test)

So far, I noticed that:

Thanks for creating the fable package and having a look at this issue :pray:. Timo

mitchelloharawild commented 2 years ago

Thanks for this issue. I've migrated this to fabletools as this issue relates to the model definition objects and how lagged elements are recalled automatically (all handled in fabletools).