business-science / modeltime

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

Tune prophet within modeltime model #246

Open Patrikios opened 5 months ago

Patrikios commented 5 months ago

As the documentation does not povide a an example for hyperparameter tuning a prophet model, I tired a simple snippet like follows:

 modeltime::prophet_reg(
    growth = growth(values = c("linear", "logistic")),
    changepoint_num = changepoint_num(range = c(0L, 50L), trans = NULL)
  ) |>
    parsnip::set_engine(
      engine = "prophet",
      holidays = generated_holidays
    ) |>
    fit(target_var ~ .,
        data = split_train
    )

which fails with

growth must be 'linear' or 'logistic'. Defaulting to 'linear'.
Disabling daily seasonality. Run prophet with daily.seasonality=TRUE to override this.
Fehler in m$n.changepoints + 1 : 
  nicht-numerisches Argument für binären Operator

Is this usage correc?

joranE commented 5 months ago

In general you specify a hyperparameter for tuning by passing, e.g. growth = tune(). There is a full walkthrough of the process here.

FColicino commented 4 months ago

Alternatively, you can use create_model_grid to create a list of model that you need to train. Below the code:

library(modeltime)
library(tidymodels)

m750

models <- 
  grid_regular(
    changepoint_num(),
    growth(),
    levels = 3) |>
  create_model_grid(
    f_model_spec = prophet_reg,
    engine_name  = "prophet",
    mode         = "regression"
  ) |>
  select(.models) |>
  pull() # or pluck(1)

preprocessing <-
  list(basic_preproc = recipe(value ~ date, data = m750))

wf <- workflow_set(preproc = preprocessing,
                   models = models)

modeltime_fit_workflowset(wf, data = m750)