
Model handler functions for API endpoint
Source:R/caret.R, R/gam.R, R/glm.R, and 12 more
handler_startup.RdThese are developer-facing functions, useful for supporting new model types.
Each model supported by vetiver_model() uses two handler functions
in vetiver_api():
The
handler_startupfunction executes when the API starts. Use this function for tasks like loading packages. A model can use the default method here, which isNULL(to do nothing at startup).The
handler_predictfunction executes at each API call. Use this function for callingpredict()and any other tasks that must be executed at each API call.
Usage
# S3 method for class 'train'
handler_startup(vetiver_model)
# S3 method for class 'train'
handler_predict(vetiver_model, ...)
# S3 method for class 'gam'
handler_startup(vetiver_model)
# S3 method for class 'gam'
handler_predict(vetiver_model, ...)
# S3 method for class 'glm'
handler_predict(vetiver_model, ...)
handler_startup(vetiver_model)
# Default S3 method
handler_startup(vetiver_model)
handler_predict(vetiver_model, ...)
# Default S3 method
handler_predict(vetiver_model, ...)
# S3 method for class 'keras.engine.training.Model'
handler_startup(vetiver_model)
# S3 method for class 'keras.engine.training.Model'
handler_predict(vetiver_model, ...)
# S3 method for class 'kproto'
handler_predict(vetiver_model, ...)
# S3 method for class 'lm'
handler_predict(vetiver_model, ...)
# S3 method for class 'luz_module_fitted'
handler_startup(vetiver_model)
# S3 method for class 'luz_module_fitted'
handler_predict(vetiver_model, ...)
# S3 method for class 'Learner'
handler_startup(vetiver_model)
# S3 method for class 'Learner'
handler_predict(vetiver_model, ...)
# S3 method for class 'int_conformal_split'
handler_startup(vetiver_model)
# S3 method for class 'int_conformal_split'
handler_predict(vetiver_model, ...)
# S3 method for class 'int_conformal_full'
handler_startup(vetiver_model)
# S3 method for class 'int_conformal_full'
handler_predict(vetiver_model, ...)
# S3 method for class 'int_conformal_quantile'
handler_startup(vetiver_model)
# S3 method for class 'int_conformal_quantile'
handler_predict(vetiver_model, ...)
# S3 method for class 'int_conformal_cv'
handler_startup(vetiver_model)
# S3 method for class 'int_conformal_cv'
handler_predict(vetiver_model, ...)
# S3 method for class 'ranger'
handler_startup(vetiver_model)
# S3 method for class 'ranger'
handler_predict(vetiver_model, ...)
# S3 method for class 'recipe'
handler_startup(vetiver_model)
# S3 method for class 'recipe'
handler_predict(vetiver_model, ...)
# S3 method for class 'model_stack'
handler_startup(vetiver_model)
# S3 method for class 'model_stack'
handler_predict(vetiver_model, ...)
# S3 method for class 'workflow'
handler_startup(vetiver_model)
# S3 method for class 'workflow'
handler_predict(vetiver_model, ...)
# S3 method for class 'xgb.Booster'
handler_startup(vetiver_model)
# S3 method for class 'xgb.Booster'
handler_predict(vetiver_model, ...)Arguments
- vetiver_model
A deployable
vetiver_model()object- ...
Other arguments passed to
predict(), such as predictiontype
Value
A handler_startup function should return invisibly, while a
handler_predict function should return a function with the signature
function(req). The request body (req$body) consists of the new data
at prediction time; this function should return predictions either as a
tibble or as a list coercable to a tibble via tibble::as_tibble().
Examples
cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "cars_linear")
handler_startup(v)
handler_predict(v)
#> function (req)
#> {
#> newdata <- req$body
#> if (!is_null(ptype)) {
#> newdata <- vetiver_type_convert(newdata, ptype)
#> newdata <- hardhat::scream(newdata, ptype)
#> }
#> ret <- predict(vetiver_model$model, newdata = newdata, ...)
#> list(.pred = ret)
#> }
#> <bytecode: 0x55aa5ae4e388>
#> <environment: 0x55aa5ae46660>