business-science / modeltime

Modeltime unlocks time series forecast models and machine learning in one framework
https://business-science.github.io/modeltime/
Other
523 stars 80 forks source link

Nested Forecasting: Error in online example #210

Closed leonhGeis closed 1 year ago

leonhGeis commented 1 year ago

Just wanted to try out the example for iterative forecasting with nested ensembles. When I run the code, I get the following error message for prophet: PROPHET_REG "CCTZ: Unrecognized output timezone: \"GMT\""

Here the example code:

library(tidymodels
        )
library(modeltime
        )
library(modeltime.ensemble
        )
library(tidyverse
        )
library(timetk
        )
data_tbl <- walmart_sales_weekly %>%
  select(id, Date, Weekly_Sales
         ) %>%
  set_names(c("id", "date", "value")) %>%
  filter(id %in% c("1_1", "1_3")
         )
nested_data_tbl <- data_tbl %>%
  # Step 1: Extend
  extend_timeseries(
    .id_var        = id,
    .date_var      = date,
    .length_future = 52
  ) %>%
  # Step 2: Nest
  nest_timeseries(
    .id_var        = id,
    .length_future = 52,
    .length_actual = 52*2
  ) %>%
  # Step 3: Split Train/Test
  split_nested_timeseries(
    .length_test = 52
  )
rec_prophet <- recipe(value ~ date, extract_nested_train_split(nested_data_tbl)
                      ) 
wflw_prophet <- workflow() %>%
  add_model(
    prophet_reg("regression", seasonality_yearly = TRUE) %>% 
      set_engine("prophet")
      ) %>%
  add_recipe(rec_prophet
             )
rec_xgb <- recipe(value ~ ., extract_nested_train_split(nested_data_tbl)) %>%
  step_timeseries_signature(date
                            ) %>%
  step_rm(date
          ) %>%
  step_zv(all_predictors()
          ) %>%
  step_dummy(all_nominal_predictors(), one_hot = TRUE
             )
wflw_xgb <- workflow() %>%
  add_model(boost_tree("regression"
                       ) %>% set_engine("xgboost")
                       ) %>%
  add_recipe(rec_xgb
             )
nested_modeltime_tbl <- modeltime_nested_fit(
  # Nested data 
  nested_data = nested_data_tbl,
  # Add workflows
  wflw_prophet,
  wflw_xgb
)
extract_nested_error_report(nested_modeltime_tbl
                            )
mdancho84 commented 1 year ago

I'm wondering if this is an issue with prophet.

What happens when you take the prophet model out of your iterative forecast inside of modeltime_nested()?

mdancho84 commented 1 year ago

Looks similar to this issue: https://stackoverflow.com/questions/73032947/error-with-timezone-when-fit-prophet-model

Solution: Reinstall lubridate package

leonhGeis commented 1 year ago

Without Prophet it works fine. Also, I just tested the code on my local machine, where it runs without issues. I am having some trouble, updating libraries on the clients side. I also guess lubridate might be the issue

mdancho84 commented 1 year ago

I'm thinking it's lubridate based on others that I remember having this problem. Try updating lubridate and let me know how it goes. 🤞

leonhGeis commented 1 year ago

Just reinstalled lubridate on the clients machine. Now it works fine. Thanks!

mdancho84 commented 1 year ago

Excellent.