Learn R Programming

modeltime.ensemble (version 0.2.0)

modeltime_fit_resamples: Fits Models in a Modeltime Table to Resamples

Description

Resampled predictions are commonly needed as part of the Ensembling Process for Stacked Ensembles, which use meta-learners. Refer to ensemble_model_spec().

Usage

modeltime_fit_resamples(object, resamples, control = control_resamples())

Arguments

object

A Modeltime Table

resamples

An rset resample object. Used to generate sub-model predictions for the meta-learner. See timetk::time_series_cv() or rsample::vfold_cv() for making resamples.

control

A tune::control_resamples() object to provide control over the resampling process.

Value

A Modeltime Table (mdl_time_tbl) object with a column containing resample results (.resample_results)

Details

The function uses tune::fit_resamples() to iteratively train and predict models contained in a Modeltime Table on resample objects. This is useful in creating Stacked Ensembles using ensemble_model_spec() because the submodel cross-validation predictions are used as the input to the meta-learner model.

One difference between tune::fit_resamples() and modeltime_fit_resamples() is that predictions are always returned (i.e. control = tune::control_resamples(save_pred = TRUE)). This is needed for ensemble_model_spec().

Examples

Run this code
# NOT RUN {
library(tidymodels)
library(modeltime)
library(modeltime.ensemble)
library(timetk)
library(tidyverse)

resamples_tscv <- training(m750_splits) %>%
    time_series_cv(
        assess      = "2 years",
        initial     = "5 years",
        skip        = "2 years",
        slice_limit = 1
    )

m750_models_resample <- m750_models %>%
    modeltime_fit_resamples(
        resamples = resamples_tscv,
        control   = control_resamples(verbose = TRUE)
    )

m750_models_resample

# }

Run the code above in your browser using DataLab