workflows-internals: Internal workflow functions

workflows-internalsR Documentation

Internal workflow functions

Description

.fit_pre(), .fit_model(), and .fit_finalize() are internal workflow functions for partially fitting a workflow object. They are only exported for usage by the tuning package, tune, and the general user should never need to worry about them.

Usage

.fit_pre(workflow, data)

.fit_model(workflow, control)

.fit_finalize(workflow)

Arguments

workflow

A workflow

For .fit_pre(), this should be a fresh workflow.

For .fit_model(), this should be a workflow that has already been trained through .fit_pre().

For .fit_finalize(), this should be a workflow that has been through both .fit_pre() and .fit_model().

data

A data frame of predictors and outcomes to use when fitting the workflow

control

A control_workflow() object

Examples

library(parsnip)
library(recipes)
library(magrittr)

model <- linear_reg() %>%
  set_engine("lm")

wf_unfit <- workflow() %>%
  add_model(model) %>%
  add_formula(mpg ~ cyl + log(disp))

wf_fit_pre <- .fit_pre(wf_unfit, mtcars)
wf_fit_model <- .fit_model(wf_fit_pre, control_workflow())
wf_fit <- .fit_finalize(wf_fit_model)

# Notice that fitting through the model doesn't mark the
# workflow as being "trained"
wf_fit_model

# Finalizing the workflow marks it as "trained"
wf_fit

# Which allows you to predict from it
try(predict(wf_fit_model, mtcars))

predict(wf_fit, mtcars)

workflows documentation built on May 29, 2024, 3:57 a.m.