# NOT RUN {
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)
pull_workflow_preprocessor(formula_workflow)
# The `spec` is the parsnip spec before it has been fit.
# The `fit` is the fit parsnip model.
pull_workflow_spec(fit_formula_workflow)
pull_workflow_fit(fit_formula_workflow)
# 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)
# A useful shortcut is to extract the prepped recipe from the workflow
pull_workflow_prepped_recipe(fit_recipe_workflow)
# That is identical to
identical(
pull_workflow_mold(fit_recipe_workflow)$blueprint$recipe,
pull_workflow_prepped_recipe(fit_recipe_workflow)
)
# }
Run the code above in your browser using DataLab