Learn R Programming

vetiver (version 0.2.7)

handler_startup.train: Model handler functions for API endpoint

Description

These 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_startup function executes when the API starts. Use this function for tasks like loading packages. A model can use the default method here, which is NULL (to do nothing at startup).

  • The handler_predict function executes at each API call. Use this function for calling predict() and any other tasks that must be executed at each API call.

Usage

# S3 method for train
handler_startup(vetiver_model)

# S3 method for train handler_predict(vetiver_model, ...)

# S3 method for gam handler_startup(vetiver_model)

# S3 method for gam handler_predict(vetiver_model, ...)

# S3 method for glm handler_predict(vetiver_model, ...)

handler_startup(vetiver_model)

# S3 method for default handler_startup(vetiver_model)

handler_predict(vetiver_model, ...)

# S3 method for default handler_predict(vetiver_model, ...)

# S3 method for keras.engine.training.Model handler_startup(vetiver_model)

# S3 method for keras.engine.training.Model handler_predict(vetiver_model, ...)

# S3 method for kproto handler_predict(vetiver_model, ...)

# S3 method for lm handler_predict(vetiver_model, ...)

# S3 method for luz_module_fitted handler_startup(vetiver_model)

# S3 method for luz_module_fitted handler_predict(vetiver_model, ...)

# S3 method for Learner handler_startup(vetiver_model)

# S3 method for Learner handler_predict(vetiver_model, ...)

# S3 method for int_conformal_split handler_startup(vetiver_model)

# S3 method for int_conformal_split handler_predict(vetiver_model, ...)

# S3 method for int_conformal_full handler_startup(vetiver_model)

# S3 method for int_conformal_full handler_predict(vetiver_model, ...)

# S3 method for int_conformal_quantile handler_startup(vetiver_model)

# S3 method for int_conformal_quantile handler_predict(vetiver_model, ...)

# S3 method for int_conformal_cv handler_startup(vetiver_model)

# S3 method for int_conformal_cv handler_predict(vetiver_model, ...)

# S3 method for ranger handler_startup(vetiver_model)

# S3 method for ranger handler_predict(vetiver_model, ...)

# S3 method for recipe handler_startup(vetiver_model)

# S3 method for recipe handler_predict(vetiver_model, ...)

# S3 method for model_stack handler_startup(vetiver_model)

# S3 method for model_stack handler_predict(vetiver_model, ...)

# S3 method for workflow handler_startup(vetiver_model)

# S3 method for workflow handler_predict(vetiver_model, ...)

# S3 method for xgb.Booster handler_startup(vetiver_model)

# S3 method for xgb.Booster handler_predict(vetiver_model, ...)

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().

Arguments

vetiver_model

A deployable vetiver_model() object

...

Other arguments passed to predict(), such as prediction type

Details

These are two generics that use the class of vetiver_model$model for dispatch.

Examples

Run this code

cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "cars_linear")
handler_startup(v)
handler_predict(v)

Run the code above in your browser using DataLab