bundle.workflow {bundle} | R Documentation |
Bundle a tidymodels workflow
object
Description
Bundling a model prepares it to be saved to a file and later restored for prediction in a new R session. See the 'Value' section for more information on bundles and their usage.
Usage
## S3 method for class 'workflow'
bundle(x, ...)
Arguments
x |
A workflow object returned from workflows or other tidymodels packages. |
... |
Not used in this bundler and included for compatibility with the generic only. Additional arguments passed to this method will return an error. |
Details
This bundler wraps bundle.model_fit()
and bundle.recipe()
.
Value
A bundle object with subclass bundled_workflow
.
Bundles are a list subclass with two components:
object |
An R object. Gives the output of native serialization methods from the model-supplying package, sometimes with additional classes or attributes that aid portability. This is often a raw object. |
situate |
A function. The |
Bundles are R objects that represent a "standalone" version of their
analogous model object. Thus, bundles are ready for saving to a file; saving
with base::saveRDS()
is our recommended serialization strategy for bundles,
unless documented otherwise for a specific method.
To restore the original model object x
in a new environment, load its
bundle with base::readRDS()
and run unbundle()
on it. The output
of unbundle()
is a model object that is ready to predict()
on new data,
and other restored functionality (like plotting or summarizing) is supported
as a side effect only.
The bundle package wraps native serialization methods from model-supplying packages. Between versions, those model-supplying packages may change their native serialization methods, possibly introducing problems with re-loading objects serialized with previous package versions. The bundle package does not provide checks for these sorts of changes, and ought to be used in conjunction with tooling for managing and monitoring model environments like vetiver or renv.
See vignette("bundle")
for more information on bundling and its motivation.
bundle and butcher
The butcher package allows you to remove parts of a fitted model object that are not needed for prediction.
This bundle method is compatible with pre-butchering. That is, for a
fitted model x
, you can safely call:
res <- x %>% butcher() %>% bundle()
and predict with the output of unbundle(res)
in a new R session.
See Also
Other bundlers:
bundle.H2OAutoML()
,
bundle.keras.engine.training.Model()
,
bundle.luz_module_fitted()
,
bundle.model_fit()
,
bundle.model_stack()
,
bundle.recipe()
,
bundle.step_umap()
,
bundle.train()
,
bundle.xgb.Booster()
,
bundle()
Examples
# fit model and bundle ------------------------------------------------
library(workflows)
library(recipes)
library(parsnip)
library(xgboost)
set.seed(1)
spec <-
boost_tree(trees = 5, mtry = 3) %>%
set_mode("regression") %>%
set_engine("xgboost")
rec <-
recipe(mpg ~ ., data = mtcars) %>%
step_log(hp)
mod <-
workflow() %>%
add_model(spec) %>%
add_recipe(rec) %>%
fit(data = mtcars)
mod_bundle <- bundle(mod)
# then, after saveRDS + readRDS or passing to a new session ----------
mod_unbundled <- unbundle(mod_bundle)