Skip to content

Optionally find and return an input data prototype for a model.

Usage

# S3 method for train
vetiver_ptype(model, ...)

# S3 method for gam
vetiver_ptype(model, ...)

# S3 method for glm
vetiver_ptype(model, ...)

# S3 method for keras.engine.training.Model
vetiver_ptype(model, ...)

# S3 method for kproto
vetiver_ptype(model, ...)

# S3 method for lm
vetiver_ptype(model, ...)

# S3 method for luz_module_fitted
vetiver_ptype(model, ...)

# S3 method for Learner
vetiver_ptype(model, ...)

vetiver_ptype(model, ...)

# S3 method for default
vetiver_ptype(model, ...)

vetiver_create_ptype(model, save_prototype, ...)

# S3 method for ranger
vetiver_ptype(model, ...)

# S3 method for recipe
vetiver_ptype(model, ...)

# S3 method for model_stack
vetiver_ptype(model, ...)

# S3 method for workflow
vetiver_ptype(model, ...)

# S3 method for xgb.Booster
vetiver_ptype(model, ...)

Arguments

model

A trained model, such as an lm() model or a tidymodels workflows::workflow().

...

Other method-specific arguments passed to vetiver_ptype() to compute an input data prototype, such as prototype_data (a sample of training features).

save_prototype

Should an input data prototype be stored with the model? The options are TRUE (the default, which stores a zero-row slice of the training data), FALSE (no input data prototype for visual documentation or checking), or a dataframe to be used for both checking at prediction time and examples in API visual documentation.

Value

A vetiver_ptype method returns a zero-row dataframe, and vetiver_create_ptype() returns either such a zero-row dataframe, NULL, or the dataframe passed to save_prototype.

Details

These are developer-facing functions, useful for supporting new model types. A vetiver_model() object optionally stores an input data prototype for checking at prediction time.

  • The default for save_prototype, TRUE, finds an input data prototype (a zero-row slice of the training data) via vetiver_ptype().

  • save_prototype = FALSE opts out of storing any input data prototype.

  • You may pass your own data to save_prototype, but be sure to check that it has the same structure as your training data, perhaps with hardhat::scream().

Examples


cars_lm <- lm(mpg ~ cyl + disp, data = mtcars)

vetiver_create_ptype(cars_lm, TRUE)
#> # A tibble: 0 × 2
#> # ℹ 2 variables: cyl <dbl>, disp <dbl>

## calls the right method for `model` via:
vetiver_ptype(cars_lm)
#> # A tibble: 0 × 2
#> # ℹ 2 variables: cyl <dbl>, disp <dbl>

## can also turn off prototype
vetiver_create_ptype(cars_lm, FALSE)
#> NULL
## some models require that you pass in training features
cars_rf <- ranger::ranger(mpg ~ ., data = mtcars)
vetiver_ptype(cars_rf, prototype_data = mtcars[,-1])
#> # A tibble: 0 × 10
#> # ℹ 10 variables: cyl <dbl>, disp <dbl>, hp <dbl>, drat <dbl>, wt <dbl>,
#> #   qsec <dbl>, vs <dbl>, am <dbl>, gear <dbl>, carb <dbl>