business-science/modeltime

Cannot tune ets_model and loss arguments in adam_reg() function.

tavad opened this issue · 1 comments

tavad commented

I am teaching myself how this function works by tuning it. I may be mistaken, but I do not think ets and loss arguments should be present in a model that is based on ARIMA. Again I may be wrong.

I was trying to tune these parameters and it trows errors as seen in the code below. PS. thanks for your contributions!!

library(dplyr)
library(parsnip)
library(rsample)
library(timetk)
library(modeltime)
library(smooth)

Data

m750 <- m4_monthly %>% filter(id == "M750")

Split Data 80/20

set.seed(1234)
splits <- initial_time_split(m750, prop = 0.8)

set.seed(456)
time_roll <-
rolling_origin(
data = training(splits),
initial = round(nrow(training(splits)) * 0.75),
assess = 24,
cumulative = TRUE,
skip = TRUE
)

recipe

rec <- recipe(value ~ date, data = training(splits)) %>%
step_log(value)

Model Spec

model_spec <-
modeltime::adam_reg(
ets_model = tune("ets"),
# loss = tune("loss")
) %>%
set_engine('adam')

selecting terms to be tuned

ets_params <-
crossing(
error = c("A", "M"),
trend = c("N", "A", "Ad", "M", "Md"),
seasonality = c("N", "A", "M")
) %>%
mutate(comb = paste0(error, trend, seasonality)) %>%
pull(comb) %>%
sample(2) # randomly selecting 2 ets terms to be tuned

loss_params <-
c("likelihood", "MSE", "MAE", "HAM", "LASSO",
"RIDGE", "MSEh", "TMSE", "GTMSE", "MSCE") %>%
sample(2) # randomly selecting 2 loss terms to be tuned

tuning the model

adam_fit <-
workflow() %>%
add_model(model_spec) %>%
add_recipe(rec) %>%
tune_grid(
resamples = time_roll,
metrics = metric_set(rmse, rsq),
grid = crossing(
ets = loss_params,
)
)

the error

 # Error in `mutate()`:
 #   ℹ In argument: `object = purrr::map(call_info, eval_call_info)`.
 # Caused by error in `purrr::map()`:
 #   ℹ In index: 1.
 # Caused by error in `.f()`:
 #   ! Error when calling ets_model(): Error : 'ets_model' is not an exported object from 'namespace:modeltime'


 # > rlang::last_trace()
 # <error/dplyr:::mutate_error>
 #   Error in `mutate()`:
 #   ℹ In argument: `object = purrr::map(call_info, eval_call_info)`.
 # Caused by error in `purrr::map()`:
 #   ℹ In index: 1.
 # Caused by error in `.f()`:
 #   ! Error when calling ets_model(): Error : 'ets_model' is not an exported object from 'namespace:modeltime'
 # ---
 #   Backtrace:
 #   ▆
 # 1. ├─... %>% ...
 # 2. ├─tune::tune_grid(...)
 # 3. ├─tune:::tune_grid.workflow(...)
 # 4. │ └─tune:::tune_grid_workflow(...)
 # 5. │   └─tune::check_parameters(...)
 # 6. │     ├─hardhat::extract_parameter_set_dials(wflow)
 # 7. │     └─workflows:::extract_parameter_set_dials.workflow(wflow)
 # 8. │       ├─hardhat::extract_parameter_set_dials(model)
 # 9. │       └─parsnip:::extract_parameter_set_dials.model_spec(model)
 # 10. │         └─... %>% ...
 # 11. ├─dplyr::mutate(., object = purrr::map(call_info, eval_call_info))
 # 12. ├─dplyr:::mutate.data.frame(., object = purrr::map(call_info, eval_call_info))
 # 13. │ └─dplyr:::mutate_cols(.data, dplyr_quosures(...), by)
 # 14. │   ├─base::withCallingHandlers(...)
 # 15. │   └─dplyr:::mutate_col(dots[[i]], data, mask, new_columns)
 # 16. │     └─mask$eval_all_mutate(quo)
 # 17. │       └─dplyr (local) eval()
 # 18. └─purrr::map(call_info, eval_call_info)
 # 19.   └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
 # 20.     ├─purrr:::with_indexed_errors(...)
 # 21.     │ └─base::withCallingHandlers(...)
 # 22.     ├─purrr:::call_with_cleanup(...)
 # 23.     └─parsnip (local) .f(.x[[i]], ...)
 # 24.       └─base::stop(paste0("Error when calling ", x$fun, "(): ", as.character(res)))
 #