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 lm
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_ptype, ...)

# S3 method for ranger
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 ptype_data (a sample of training features).

save_ptype

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_ptype.

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_ptype, TRUE, finds an input data prototype (a zero-row slice of the training data) via vetiver_ptype().

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

  • You may pass your own data to save_ptype, 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
#> # … with 2 variables: cyl <dbl>, disp <dbl>

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

## can also turn off `ptype`
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, ptype_data = mtcars[,-1])
#> # A tibble: 0 × 10
#> # … with 10 variables: cyl <dbl>, disp <dbl>, hp <dbl>, drat <dbl>,
#> #   wt <dbl>, qsec <dbl>, vs <dbl>, am <dbl>, gear <dbl>, carb <dbl>