Skip to contents

This function is a helper function. It will take in a set of workflows and then perform the modeltime::modeltime_calibrate() and modeltime::plot_modeltime_forecast().

Usage

calibrate_and_plot(
  ...,
  .type = "testing",
  .splits_obj,
  .data,
  .print_info = TRUE,
  .interactive = FALSE
)

Arguments

...

The workflow(s) you want to add to the function.

.type

Either the training(splits) or testing(splits) data.

.splits_obj

The splits object.

.data

The full data set.

.print_info

The default is TRUE and will print out the calibration accuracy tibble and the resulting plotly plot.

.interactive

The defaults is FALSE. This controls if a forecast plot is interactive or not via plotly.

Value

The original time series, the simulated values and a some plots

Details

This function expects to take in workflows fitted with training data.

Author

Steven P. Sanderson II, MPH

Examples

if (FALSE) { # \dontrun{
suppressPackageStartupMessages(library(timetk))
suppressPackageStartupMessages(library(dplyr))
suppressPackageStartupMessages(library(recipes))
suppressPackageStartupMessages(library(rsample))
suppressPackageStartupMessages(library(parsnip))
suppressPackageStartupMessages(library(workflows))

data <- ts_to_tbl(AirPassengers) %>%
  select(-index)

splits <- timetk::time_series_split(
   data
  , date_col
  , assess = 12
  , skip = 3
  , cumulative = TRUE
)

rec_obj <- recipe(value ~ ., data = training(splits))

model_spec <- linear_reg(
   mode = "regression"
   , penalty = 0.1
   , mixture = 0.5
) %>%
   set_engine("lm")

wflw <- workflow() %>%
   add_recipe(rec_obj) %>%
   add_model(model_spec) %>%
   fit(training(splits))

output <- calibrate_and_plot(
  wflw
  , .type = "training"
  , .splits_obj = splits
  , .data = data
  , .print_info = FALSE
  , .interactive = FALSE
 )
} # }