These functions extract various elements from a workflow object. If they do not exist yet, an error is thrown.

  • pull_workflow_preprocessor() returns either the formula or recipe used for preprocessing.

  • pull_workflow_spec() returns the parsnip model specification.

  • pull_workflow_fit() returns the parsnip model fit.

  • pull_workflow_mold() returns the preprocessed "mold" object returned from hardhat::mold(). It contains information about the preprocessing, including either the prepped recipe or the formula terms object.

  • pull_workflow_prepped_recipe() returns the prepped recipe. It is extracted from the mold object returned from pull_workflow_mold().

pull_workflow_preprocessor(x)

pull_workflow_spec(x)

pull_workflow_fit(x)

pull_workflow_mold(x)

pull_workflow_prepped_recipe(x)

Arguments

x

A workflow

Value

The extracted value from the workflow, x, as described in the description section.

Examples

library(parsnip) library(recipes) model <- linear_reg() model <- set_engine(model, "lm") recipe <- recipe(mpg ~ cyl + disp, mtcars) recipe <- step_log(recipe, disp) base_workflow <- workflow() base_workflow <- add_model(base_workflow, model) recipe_workflow <- add_recipe(base_workflow, recipe) formula_workflow <- add_formula(base_workflow, mpg ~ cyl + log(disp)) fit_recipe_workflow <- fit(recipe_workflow, mtcars) fit_formula_workflow <- fit(formula_workflow, mtcars) # The preprocessor is either a recipe or a formula pull_workflow_preprocessor(recipe_workflow)
#> Data Recipe #> #> Inputs: #> #> role #variables #> outcome 1 #> predictor 2 #> #> Operations: #> #> Log transformation on disp
pull_workflow_preprocessor(formula_workflow)
#> mpg ~ cyl + log(disp) #> <environment: 0x7667e18>
# The `spec` is the parsnip spec before it has been fit. # The `fit` is the fit parsnip model. pull_workflow_spec(fit_formula_workflow)
#> Linear Regression Model Specification (regression) #> #> Computational engine: lm #>
pull_workflow_fit(fit_formula_workflow)
#> parsnip model object #> #> Fit time: 1ms #> #> Call: #> stats::lm(formula = formula, data = data) #> #> Coefficients: #> (Intercept) cyl `log(disp)` #> 67.6674 -0.1755 -8.7971 #>
# The mold is returned from `hardhat::mold()`, and contains the # predictors, outcomes, and information about the preprocessing # for use on new data at `predict()` time. pull_workflow_mold(fit_recipe_workflow)
#> $predictors #> # A tibble: 32 x 2 #> cyl disp #> <dbl> <dbl> #> 1 6 5.08 #> 2 6 5.08 #> 3 4 4.68 #> 4 6 5.55 #> 5 8 5.89 #> 6 6 5.42 #> 7 8 5.89 #> 8 4 4.99 #> 9 4 4.95 #> 10 6 5.12 #> # … with 22 more rows #> #> $outcomes #> # A tibble: 32 x 1 #> mpg #> <dbl> #> 1 21 #> 2 21 #> 3 22.8 #> 4 21.4 #> 5 18.7 #> 6 18.1 #> 7 14.3 #> 8 24.4 #> 9 22.8 #> 10 19.2 #> # … with 22 more rows #> #> $blueprint #> Recipe blueprint: #> #> # Predictors: 2 #> # Outcomes: 1 #> Intercept: FALSE #> Novel Levels: FALSE #> #> $extras #> $extras$roles #> NULL #> #>
# A useful shortcut is to extract the prepped recipe from the workflow pull_workflow_prepped_recipe(fit_recipe_workflow)
#> Data Recipe #> #> Inputs: #> #> role #variables #> outcome 1 #> predictor 2 #> #> Training data contained 32 data points and no missing data. #> #> Operations: #> #> Log transformation on disp [trained]
# That is identical to identical( pull_workflow_mold(fit_recipe_workflow)$blueprint$recipe, pull_workflow_prepped_recipe(fit_recipe_workflow) )
#> [1] TRUE