predict-workflow: Predict from a workflow

Description Usage Arguments Value Examples

Description

This is the predict() method for a fit workflow object. The nice thing about predicting from a workflow is that it will:

Usage

1
2
## S3 method for class 'workflow'
predict(object, new_data, type = NULL, opts = list(), ...)

Arguments

object

A workflow that has been fit by fit.workflow()

new_data

A data frame containing the new predictors to preprocess and predict on

type

A single character value or NULL. Possible values are "numeric", "class", "prob", "conf_int", "pred_int", "quantile", or "raw". When NULL, predict() will choose an appropriate value based on the model's mode.

opts

A list of optional arguments to the underlying predict function that will be used when type = "raw". The list should not include options for the model object or the new data being predicted.

...

Arguments to the underlying model's prediction function cannot be passed here (see opts). There are some parsnip related options that can be passed, depending on the value of type. Possible arguments are:

  • level: for types of "conf_int" and "pred_int" this is the parameter for the tail area of the intervals (e.g. confidence level for confidence intervals). Default value is 0.95.

  • std_error: add the standard error of fit or prediction for types of "conf_int" and "pred_int". Default value is FALSE.

  • quantile: the quantile(s) for quantile regression (not implemented yet)

  • time: the time(s) for hazard probability estimates (not implemented yet)

Value

A data frame of model predictions, with as many rows as new_data has.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
library(parsnip)
library(recipes)

training <- mtcars[1:20,]
testing <- mtcars[21:32,]

model <- linear_reg()
model <- set_engine(model, "lm")

workflow <- workflow()
workflow <- add_model(workflow, model)

recipe <- recipe(mpg ~ cyl + disp, training)
recipe <- step_log(recipe, disp)

workflow <- add_recipe(workflow, recipe)

fit_workflow <- fit(workflow, training)

# This will automatically `bake()` the recipe on `testing`,
# applying the log step to `disp`, and then fit the regression.
predict(fit_workflow, testing)

tidymodels/workflows documentation built on Jan. 3, 2020, 4:47 a.m.