Learn R Programming

parsnip (version 0.0.0.9000)

fit: Fit a Model Specification to a Dataset

Description

fit will take a model specification, finalize the required code by substituting arguments, and execute the model fit routine.

Usage

fit(object, ...)

# S3 method for model_spec fit(object, x, engine = object$engine, .control = list(verbosity = 1, catch = FALSE), ...)

Arguments

object

An object of class model_spec

...

Other options required to fit the model. If x is a formula or recipe, then the data argument should be passed here. For the "x/y" interface, the outcome data should be passed in with the argument y.

x

Either an R formula, a data frame of predictors, or a recipe object.

engine

A character string for the software that should be used to fit the model. This is highly dependent on the type of model (e.g. linear regression, random forest, etc.).

.control

A named list with elements verbosity and catch. verbosity should be an integer where a value of zero indicates that no messages or output should be shown when packages are loaded or when the model is fit. A value of 1 means that package loading is quiet but model fits can produce output to the screen (depending on if they contain their own verbose-type argument). A value of 2 or more indicates that any output should be seen. catch is a logical where a value of TRUE will evaluate the model inside of try(, silent = TRUE). If the model fails, an object is still returned (without an error) that inherits the class "try-error".

Value

An object for the fitted model.

Details

fit substitutes the current arguments in the model specification into the computational engine's code, checks them for validity, then fits the model using the data and the engine-specific code. Different model functions have different interfaces (e.g. formula or x/y) and fit translates between the interface used when fit was invoked and the one required by the underlying model.

When possible, fit attempts to avoid making copies of the data. For example, if the underlying model uses a formula and fit is invoked with a formula, the original data are references when the model is fit. However, if the underlying model uses something else, such as x/y, the formula is evaluated and the data are converted to the required format. In this case, any calls in the resulting model objects reference the temporary objects used to fit the model.