Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

modeltime_calibrate

Preparation for forecasting


Description

Calibration sets the stage for accuracy and forecast confidence by computing predictions and residuals from out of sample data.

Usage

modeltime_calibrate(object, new_data, quiet = TRUE, ...)

Arguments

object

A fitted model object that is either:

  1. A modeltime table that has been created using modeltime_table()

  2. A workflow that has been fit by fit.workflow() or

  3. A parsnip model that has been fit using fit.model_spec()

new_data

A test data set tibble containing future information (timestamps and actual values).

quiet

Hide errors (TRUE, the default), or display them as they occur?

...

Additional arguments passed to modeltime_forecast().

Details

The results of calibration are used for:

  • Forecast Confidence Interval Estimation: The out of sample residual data is used to calculate the confidence interval. Refer to modeltime_forecast().

  • Accuracy Calculations: The out of sample actual and prediction values are used to calculate performance metrics. Refer to modeltime_accuracy()

The calibration steps include:

  1. If not a Modeltime Table, objects are converted to Modeltime Tables internally

  2. Two Columns are added:

  • .type: Indicates the sample type. Only "Test" is currently available.

  • .calibration_data: Contains a tibble with Timestamps, Actual Values, Predictions and Residuals calculated from new_data (Test Data)

Value

A Modeltime Table (mdl_time_tbl) with nested .calibration_data added

Examples

library(tidyverse)
library(lubridate)
library(timetk)
library(parsnip)
library(rsample)

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

# Split Data 80/20
splits <- initial_time_split(m750, prop = 0.9)

# --- MODELS ---

# Model 1: auto_arima ----
model_fit_arima <- arima_reg() %>%
    set_engine(engine = "auto_arima") %>%
    fit(value ~ date, data = training(splits))


# ---- MODELTIME TABLE ----

models_tbl <- modeltime_table(
    model_fit_arima
)

# ---- CALIBRATE ----

calibration_tbl <- models_tbl %>%
    modeltime_calibrate(new_data = testing(splits))

# ---- ACCURACY ----

calibration_tbl %>%
    modeltime_accuracy()

# ---- FORECAST ----

calibration_tbl %>%
    modeltime_forecast(
        new_data    = testing(splits),
        actual_data = m750
    )

modeltime

The Tidymodels Extension for Time Series Modeling

v0.5.1
MIT + file LICENSE
Authors
Matt Dancho [aut, cre], Business Science [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.