Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tune engine specific arguments: error on finalize_workflow #195

Closed
AlbertoAlmuinha opened this issue Aug 9, 2022 · 0 comments
Closed

tune engine specific arguments: error on finalize_workflow #195

AlbertoAlmuinha opened this issue Aug 9, 2022 · 0 comments

Comments

@AlbertoAlmuinha
Copy link
Contributor

The problem

I'm having trouble when trying to finish the workflow after applying the tune_grid function through worfklow_map. When I extract the best hyperparameters and introduce them in the finalize_workflow() function I get the following error as one of them is engine specific.

Here is a related problem with a solution: tidymodels/tune#254

I think it is necessary to change the update method of the definition of the arima model. Not sure if maybe others as well, I just try arima.

Error in `parsnip::update_dot_check()` at modeltime/R/parsnip-arima_reg.R:258:4:
! Extra arguments will be ignored: `include.mean`

Reproducible example

``` r
library(tidymodels)
#> Warning: package 'tidymodels' was built under R version 4.1.3
#> Warning: package 'broom' was built under R version 4.1.3
#> Warning: package 'dials' was built under R version 4.1.3
#> Warning: package 'dplyr' was built under R version 4.1.3
#> Warning: package 'ggplot2' was built under R version 4.1.3
#> Warning: package 'infer' was built under R version 4.1.3
#> Warning: package 'modeldata' was built under R version 4.1.3
#> Warning: package 'parsnip' was built under R version 4.1.3
#> Warning: package 'recipes' was built under R version 4.1.3
#> Warning: package 'rsample' was built under R version 4.1.3
#> Warning: package 'tibble' was built under R version 4.1.3
#> Warning: package 'tidyr' was built under R version 4.1.3
#> Warning: package 'tune' was built under R version 4.1.3
#> Warning: package 'workflows' was built under R version 4.1.3
#> Warning: package 'workflowsets' was built under R version 4.1.3
#> Warning: package 'yardstick' was built under R version 4.1.3
library(modeltime)
library(modeltime.resample)
library(timetk)
#> Warning: package 'timetk' was built under R version 4.1.3
library(tidyverse)

full_data_tbl <- walmart_sales_weekly %>%
  select(id, Date, Weekly_Sales) %>%
  
  # Apply Group-wise Time Series Manipulations
  group_by(id) %>%
  future_frame(
    .date_var   = Date,
    .length_out = "3 months",
    .bind_data  = TRUE
  ) %>%
  ungroup() %>%
  
  # Consolidate IDs
  mutate(id = fct_drop(id))

# Training Data
data_prepared_tbl <- full_data_tbl %>%
  filter(!is.na(Weekly_Sales))

walmart_tscv <- data_prepared_tbl %>%
  time_series_cv(
    date_var    = Date, 
    assess      = "3 months",
    skip        = "3 months",
    cumulative  = TRUE,
    slice_limit = 6
  )
#> Data is not ordered by the 'date_var'. Resamples will be arranged by `Date`.
#> Overlapping Timestamps Detected. Processing overlapping time series together using sliding windows.

recipe_spec <- recipe(Weekly_Sales ~ ., 
                      data = training(walmart_tscv$splits[[1]])) %>%
  step_filter(id == "1_1") %>%
  step_rm(id) 


arima_spec <- arima_reg(non_seasonal_ar = tune(), 
                        non_seasonal_differences = tune(),
                        non_seasonal_ma = tune()) %>%
              set_engine("arima", include.mean = tune())


wfset <- workflow_set(
          preproc = list(rec = recipe_spec),
          models = list(arima = arima_spec),
          cross = TRUE
        ) %>%
        option_add(grid = crossing(non_seasonal_ar = 1:1, 
                                   non_seasonal_differences = 1:1, 
                                   non_seasonal_ma = 1:4, 
                                   include.mean = 1:1) %>%
                     mutate(include.mean = TRUE))


grid_results <- 
  wfset %>% 
  workflow_map("tune_grid", 
               resamples = walmart_tscv, 
               seed = 123,
               metrics = default_forecast_accuracy_metric_set(), 
               verbose = TRUE)
#> i 1 of 1 tuning:     rec_arima
#> Registered S3 method overwritten by 'quantmod':
#>   method            from
#>   as.zoo.data.frame zoo
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 13 observations per 1 quarter
#> frequency = 12.5 observations per 1 quarter
#> frequency = 12.5 observations per 1 quarter
#> frequency = 12.5 observations per 1 quarter
#> frequency = 12.5 observations per 1 quarter
#> v 1 of 1 tuning:     rec_arima (10.4s)


best_results <- 
  grid_results %>% 
  extract_workflow_set_result("rec_arima") %>% 
  select_best(metric = "rmse")


test_results <- 
  grid_results %>% 
  extract_workflow("rec_arima") %>% 
  finalize_workflow(best_results)
#> Error in `parsnip::update_dot_check()` at modeltime/R/parsnip-arima_reg.R:258:4:
#> ! Extra arguments will be ignored: `include.mean`

Created on 2022-08-09 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value
#>  version  R version 4.1.0 (2021-05-18)
#>  os       Windows 10 x64 (build 19043)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  Spanish_Spain.1252
#>  ctype    Spanish_Spain.1252
#>  tz       Europe/Paris
#>  date     2022-08-09
#>  pandoc   2.18 @ C:/Program Files/RStudio/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package            * version    date (UTC) lib source
#>  assertthat           0.2.1      2019-03-21 [1] CRAN (R 4.1.0)
#>  backports            1.2.1      2020-12-09 [1] CRAN (R 4.1.0)
#>  broom              * 1.0.0      2022-07-01 [1] CRAN (R 4.1.3)
#>  cellranger           1.1.0      2016-07-27 [1] CRAN (R 4.1.0)
#>  class                7.3-19     2021-05-03 [2] CRAN (R 4.1.0)
#>  cli                  3.3.0      2022-04-25 [1] CRAN (R 4.1.3)
#>  codetools            0.2-18     2020-11-04 [2] CRAN (R 4.1.0)
#>  colorspace           2.0-1      2021-05-04 [1] CRAN (R 4.1.0)
#>  crayon               1.4.1      2021-02-08 [1] CRAN (R 4.1.0)
#>  curl                 4.3.1      2021-04-30 [1] CRAN (R 4.1.0)
#>  DBI                  1.1.1      2021-01-15 [1] CRAN (R 4.1.0)
#>  dbplyr               2.1.1      2021-04-06 [1] CRAN (R 4.1.0)
#>  dials              * 1.0.0      2022-06-14 [1] CRAN (R 4.1.3)
#>  DiceDesign           1.9        2021-02-13 [1] CRAN (R 4.1.0)
#>  digest               0.6.27     2020-10-24 [1] CRAN (R 4.1.0)
#>  dplyr              * 1.0.9      2022-04-28 [1] CRAN (R 4.1.3)
#>  ellipsis             0.3.2      2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate             0.14       2019-05-28 [1] CRAN (R 4.1.0)
#>  fansi                0.4.2      2021-01-15 [1] CRAN (R 4.1.0)
#>  fastmap              1.1.0      2021-01-25 [1] CRAN (R 4.1.0)
#>  forcats            * 0.5.1      2021-01-27 [1] CRAN (R 4.1.0)
#>  foreach              1.5.1      2020-10-15 [1] CRAN (R 4.1.0)
#>  forecast           * 8.14       2021-03-11 [1] CRAN (R 4.1.0)
#>  fracdiff             1.5-1      2020-01-24 [1] CRAN (R 4.1.0)
#>  fs                   1.5.0      2020-07-31 [1] CRAN (R 4.1.0)
#>  furrr                0.2.2      2021-01-29 [1] CRAN (R 4.1.0)
#>  future               1.21.0     2020-12-10 [1] CRAN (R 4.1.0)
#>  generics             0.1.3      2022-07-05 [1] CRAN (R 4.1.3)
#>  ggplot2            * 3.3.6      2022-05-03 [1] CRAN (R 4.1.3)
#>  globals              0.14.0     2020-11-22 [1] CRAN (R 4.1.0)
#>  glue                 1.6.2      2022-02-24 [1] CRAN (R 4.1.3)
#>  gower                0.2.2      2020-06-23 [1] CRAN (R 4.1.0)
#>  GPfit                1.0-8      2019-02-08 [1] CRAN (R 4.1.0)
#>  gtable               0.3.0      2019-03-25 [1] CRAN (R 4.1.0)
#>  hardhat              1.2.0      2022-06-30 [1] CRAN (R 4.1.3)
#>  haven                2.4.1      2021-04-23 [1] CRAN (R 4.1.0)
#>  highr                0.9        2021-04-16 [1] CRAN (R 4.1.0)
#>  hms                  1.1.0      2021-05-17 [1] CRAN (R 4.1.0)
#>  htmltools            0.5.2      2021-08-25 [1] CRAN (R 4.1.3)
#>  httr                 1.4.2      2020-07-20 [1] CRAN (R 4.1.0)
#>  infer              * 1.0.2      2022-06-10 [1] CRAN (R 4.1.3)
#>  ipred                0.9-13     2022-06-02 [1] CRAN (R 4.1.3)
#>  iterators            1.0.13     2020-10-15 [1] CRAN (R 4.1.0)
#>  janitor              2.1.0      2021-01-05 [1] CRAN (R 4.1.0)
#>  jsonlite             1.7.2      2020-12-09 [1] CRAN (R 4.1.0)
#>  knitr                1.33       2021-04-24 [1] CRAN (R 4.1.0)
#>  lattice              0.20-44    2021-05-02 [2] CRAN (R 4.1.0)
#>  lava                 1.6.9      2021-03-11 [1] CRAN (R 4.1.0)
#>  lhs                  1.1.1      2020-10-05 [1] CRAN (R 4.1.0)
#>  lifecycle            1.0.1      2021-09-24 [1] CRAN (R 4.1.3)
#>  listenv              0.8.0      2019-12-05 [1] CRAN (R 4.1.0)
#>  lmtest               0.9-38     2020-09-09 [1] CRAN (R 4.1.0)
#>  lubridate            1.8.0      2021-10-07 [1] CRAN (R 4.1.3)
#>  magrittr             2.0.1      2020-11-17 [1] CRAN (R 4.1.0)
#>  MASS                 7.3-54     2021-05-03 [2] CRAN (R 4.1.0)
#>  Matrix               1.3-3      2021-05-04 [2] CRAN (R 4.1.0)
#>  modeldata          * 1.0.0      2022-07-01 [1] CRAN (R 4.1.3)
#>  modelr               0.1.8      2020-05-19 [1] CRAN (R 4.1.0)
#>  modeltime          * 1.2.2.9000 2022-08-09 [1] local
#>  modeltime.resample * 0.2.0      2021-03-14 [1] CRAN (R 4.1.0)
#>  munsell              0.5.0      2018-06-12 [1] CRAN (R 4.1.0)
#>  nlme                 3.1-152    2021-02-04 [2] CRAN (R 4.1.0)
#>  nnet                 7.3-16     2021-05-03 [2] CRAN (R 4.1.0)
#>  parallelly           1.25.0     2021-04-30 [1] CRAN (R 4.1.0)
#>  parsnip            * 1.0.0      2022-06-16 [1] CRAN (R 4.1.3)
#>  pillar               1.8.0      2022-07-18 [1] CRAN (R 4.1.3)
#>  pkgconfig            2.0.3      2019-09-22 [1] CRAN (R 4.1.0)
#>  prettyunits          1.1.1      2020-01-24 [1] CRAN (R 4.1.0)
#>  prodlim              2019.11.13 2019-11-17 [1] CRAN (R 4.1.0)
#>  purrr              * 0.3.4      2020-04-17 [1] CRAN (R 4.1.0)
#>  quadprog             1.5-8      2019-11-20 [1] CRAN (R 4.1.0)
#>  quantmod             0.4.18     2020-12-09 [1] CRAN (R 4.1.0)
#>  R6                   2.5.0      2020-10-28 [1] CRAN (R 4.1.0)
#>  Rcpp                 1.0.7      2021-07-07 [1] CRAN (R 4.1.0)
#>  readr              * 1.4.0      2020-10-05 [1] CRAN (R 4.1.0)
#>  readxl               1.3.1      2019-03-13 [1] CRAN (R 4.1.0)
#>  recipes            * 1.0.1      2022-07-07 [1] CRAN (R 4.1.3)
#>  reprex               2.0.1      2021-08-05 [1] CRAN (R 4.1.3)
#>  rlang                1.0.4      2022-07-12 [1] CRAN (R 4.1.3)
#>  rmarkdown            2.8        2021-05-07 [1] CRAN (R 4.1.0)
#>  rpart                4.1-15     2019-04-12 [2] CRAN (R 4.1.0)
#>  rsample            * 1.0.0      2022-06-24 [1] CRAN (R 4.1.3)
#>  rstudioapi           0.13       2020-11-12 [1] CRAN (R 4.1.0)
#>  rvest                1.0.0      2021-03-09 [1] CRAN (R 4.1.0)
#>  scales             * 1.1.1      2020-05-11 [1] CRAN (R 4.1.0)
#>  sessioninfo          1.2.2      2021-12-06 [1] CRAN (R 4.1.3)
#>  snakecase            0.11.0     2019-05-25 [1] CRAN (R 4.1.0)
#>  stringi              1.6.2      2021-05-17 [1] CRAN (R 4.1.0)
#>  stringr            * 1.4.0      2019-02-10 [1] CRAN (R 4.1.0)
#>  styler               1.5.1      2021-07-13 [1] CRAN (R 4.1.0)
#>  survival             3.2-11     2021-04-26 [2] CRAN (R 4.1.0)
#>  tibble             * 3.1.8      2022-07-22 [1] CRAN (R 4.1.3)
#>  tidymodels         * 1.0.0      2022-07-13 [1] CRAN (R 4.1.3)
#>  tidyr              * 1.2.0      2022-02-01 [1] CRAN (R 4.1.3)
#>  tidyselect           1.1.2      2022-02-21 [1] CRAN (R 4.1.3)
#>  tidyverse          * 1.3.1      2021-04-15 [1] CRAN (R 4.1.0)
#>  timeDate             3043.102   2018-02-21 [1] CRAN (R 4.1.0)
#>  timetk             * 2.8.1      2022-05-31 [1] CRAN (R 4.1.3)
#>  tseries              0.10-48    2020-12-04 [1] CRAN (R 4.1.0)
#>  TTR                  0.24.2     2020-09-01 [1] CRAN (R 4.1.0)
#>  tune               * 1.0.0      2022-07-07 [1] CRAN (R 4.1.3)
#>  urca                 1.3-0      2016-09-06 [1] CRAN (R 4.1.0)
#>  utf8                 1.2.1      2021-03-12 [1] CRAN (R 4.1.0)
#>  vctrs                0.4.1      2022-04-13 [1] CRAN (R 4.1.3)
#>  withr                2.4.2      2021-04-18 [1] CRAN (R 4.1.0)
#>  workflows          * 1.0.0      2022-07-05 [1] CRAN (R 4.1.3)
#>  workflowsets       * 1.0.0      2022-07-12 [1] CRAN (R 4.1.3)
#>  xfun                 0.23       2021-05-15 [1] CRAN (R 4.1.0)
#>  xml2                 1.3.2      2020-04-23 [1] CRAN (R 4.1.0)
#>  xts                  0.12.1     2020-09-09 [1] CRAN (R 4.1.0)
#>  yaml                 2.2.1      2020-02-01 [1] CRAN (R 4.1.0)
#>  yardstick          * 1.0.0      2022-06-06 [1] CRAN (R 4.1.3)
#>  zoo                  1.8-9      2021-03-09 [1] CRAN (R 4.1.0)
#> 
#>  [1] C:/Users/Usuario/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.0/library
#> 
#> ------------------------------------------------------------------------------
AlbertoAlmuinha added a commit to AlbertoAlmuinha/modeltime that referenced this issue Aug 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant