modeltime_calibrate {modeltime} | R Documentation |
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, id = NULL, quiet = TRUE, ...)
Arguments
object |
A fitted model object that is either:
|
new_data |
A test data set |
id |
A quoted column name containing an identifier column identifying time series that are grouped. |
quiet |
Hide errors ( |
... |
Additional arguments passed to |
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:
If not a Modeltime Table, objects are converted to Modeltime Tables internally
Two Columns are added:
-
.type
: Indicates the sample type. This is:"Test" if predicted, or
"Fitted" if residuals were stored during modeling.
-
.calibration_data
:Contains a tibble with Timestamps, Actual Values, Predictions and Residuals calculated from
new_data
(Test Data)If
id
is provided, will contain a 5th column that is the identifier variable.
Value
A Modeltime Table (mdl_time_tbl
) with nested .calibration_data
added
Examples
library(dplyr)
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.8)
# --- MODELS ---
# Model 1: prophet ----
model_fit_prophet <- prophet_reg() %>%
set_engine(engine = "prophet") %>%
fit(value ~ date, data = training(splits))
# ---- MODELTIME TABLE ----
models_tbl <- modeltime_table(
model_fit_prophet
)
# ---- 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
)