business-science / modeltime.gluonts

GluonTS Deep Learning with Modeltime
https://business-science.github.io/modeltime.gluonts/
Other
39 stars 9 forks source link

Dials Helpers: Create tuning functions for specifications #14

Open mdancho84 opened 3 years ago

mdancho84 commented 3 years ago

Problem

Code like this fails.

model_spec_deepar_tune <- deep_ar(
    id                    = "id",
    freq                  = "W",
    prediction_length     = 12,
    lookback_length       = tune(),
    num_batches_per_epoch = tune(),
    epochs                = 2,
    cell_type             = "lstm"
) %>%
    set_engine("gluonts_deepar")

gluonts_grid <- expand_grid(
    lookback_length = c(12, 18, 24, 36),
    num_batches_per_epoch = c(10, 25, 35, 50)
    )
wflw_deep_tune <- workflow() %>%
    add_model(model_spec_deepar_tune) %>%
    add_recipe(recipe_spec_gluon)
deep_ar_tune <- tune_grid(
    wflw_deep_tune,
    resamples = resamples_tscv,
    param_info = NULL,
    grid = gluonts_grid,
    control = control_grid(verbose = TRUE)
)

Error Returned:

Error when calling lookback_length(): Error : 'lookback_length' is not an exported object from 'namespace:modeltime.gluonts'

Proposed Solution

Create dials functions for tuning parameters.

flrs commented 3 years ago

Where would those functions have to be created? Here in modeltime.gluonts or over at https://github.com/tidymodels/dials/?

mdancho84 commented 3 years ago

Hey @flrs , the way I would do it is in the modeltime.gluonts package by creating a file named: dials-deepar_params.R and adding the missing functions.

An example is in modeltime for dials-prophet_params.R: https://github.com/business-science/modeltime/blob/master/R/dials-prophet_params.R

We need to be careful because we don't want to overwrite other dials parameters that may exist. Otherwise, I'll get hate-mail saying my function is overwriting another tidymodels or R package's function. A few packages we can review are:

The important thing is to either use the same function as a common dials package or to create something new that others won't overwrite.