Skip to content

These are developer-facing functions, useful for supporting new model types. Each model supported by vetiver_model() uses up to four methods when the deployable object is created:

  • The vetiver_create_description() function generates a helpful description of the model based on its characteristics. This method is required.

  • The vetiver_create_meta() function creates the correct vetiver_meta() for the model. This is especially helpful for specifying which packages are needed for prediction. A model can use the default method here, which is to have no special metadata.

  • The vetiver_ptype() function finds an input data prototype from the training data (a zero-row slice) to use for checking at prediction time. This method is required.

  • The vetiver_prepare_model() function executes last. Use this function for tasks like checking if the model is trained and reducing the size of the model via butcher::butcher(). A model can use the default method here, which is to return the model without changes.

Usage

# S3 method for train
vetiver_create_description(model)

# S3 method for train
vetiver_prepare_model(model)

# S3 method for glm
vetiver_create_description(model)

# S3 method for glm
vetiver_prepare_model(model)

# S3 method for lm
vetiver_create_description(model)

# S3 method for lm
vetiver_prepare_model(model)

# S3 method for Learner
vetiver_create_description(model)

# S3 method for Learner
vetiver_prepare_model(model)

vetiver_create_description(model)

# S3 method for default
vetiver_create_description(model)

vetiver_prepare_model(model)

# S3 method for default
vetiver_prepare_model(model)

# S3 method for ranger
vetiver_create_description(model)

# S3 method for ranger
vetiver_prepare_model(model)

# S3 method for workflow
vetiver_create_description(model)

# S3 method for workflow
vetiver_prepare_model(model)

# S3 method for xgb.Booster
vetiver_create_description(model)

Arguments

model

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

Details

These are four generics that use the class of model for dispatch.

Examples


cars_lm <- lm(mpg ~ ., data = mtcars)
vetiver_create_description(cars_lm)
#> [1] "An OLS linear regression model"
vetiver_prepare_model(cars_lm)
#> 
#> Call:
#> dummy_call()
#> 
#> Coefficients:
#> (Intercept)          cyl         disp           hp         drat  
#>    12.30337     -0.11144      0.01334     -0.02148      0.78711  
#>          wt         qsec           vs           am         gear  
#>    -3.71530      0.82104      0.31776      2.52023      0.65541  
#>        carb  
#>    -0.19942  
#>