plug_resample() specifies the type of resample used in the analysis. It
accepts a function .f that will be applied to the raw data. Only
functions which return an rset object will be allowed. See
package rsample and the details section.
drop_resample() removes the resample specification from the tidyflow.
Note that it keeps other preprocessing steps such as the recipe.
replace_resample() first removes the resample, then adds a new resample
specification. Any model that has already been fit based on this
split will need to be refit.
plug_resample(x, .f, ...)
drop_resample(x)
replace_resample(x, .f, ...)A tidyflow
A function to be applied to the dataset in the tidyflow. Must
return an object of class rset. See package
rsample.
arguments passed to .f. These arguments must be named.
The processing of ... respects the quotation rules from .f.
In other words, if the function allows variables as strings and
as names, the user can specify both. See the example sections.
The tidyflow x, updated with either a new or removed resample specification.
The resample specification is an optional step in the tidyflow. You can add a dataframe, prepare a recipe and fit the model without adding a resample.
When applied to the data, the function .f must return an object
of class rset. These are functions which come from the
rsample package such as
vfold_cv and bootstraps.
library(tibble)
library(rsample)
wf <-
mtcars %>%
tidyflow() %>%
plug_resample(vfold_cv, v = 5, strata = "cyl")
wf
#> ══ Tidyflow ════════════════════════════════════════════════════════════════════
#> Data: 32 rows x 11 columns
#> Split: None
#> Recipe/Formula: None
#> Resample: vfold_cv w/ v = ~5, strata = ~"cyl"
#> Grid: None
#> Model: None
# Strata as unquoted name
wf <- replace_resample(wf, initial_split, v = 5, strata = cyl)
wf
#> ══ Tidyflow ════════════════════════════════════════════════════════════════════
#> Data: 32 rows x 11 columns
#> Split: None
#> Recipe/Formula: None
#> Resample: initial_split w/ v = ~5, strata = ~cyl
#> Grid: None
#> Model: None
drop_resample(wf)
#> ══ Tidyflow ════════════════════════════════════════════════════════════════════
#> Data: 32 rows x 11 columns
#> Split: None
#> Recipe/Formula: None
#> Resample: None
#> Grid: None
#> Model: None
# New split function
replace_resample(wf, bootstraps)
#> ══ Tidyflow ════════════════════════════════════════════════════════════════════
#> Data: 32 rows x 11 columns
#> Split: None
#> Recipe/Formula: None
#> Resample: bootstraps w/ default args
#> Grid: None
#> Model: None