/vetiver

Version, share, deploy, and monitor models

Primary LanguageROtherNOASSERTION

vetiver 🏺

Lifecycle: experimental R-CMD-check Codecov test coverage

This pre-release is available for feedback and experimenting.

Vetiver, the oil of tranquility, is used as a stabilizing ingredient in perfumery to preserve more volatile fragrances.

The goal of vetiver is to provide fluent tooling to version, share, deploy, and monitor a trained model. Functions handle both recording and checking the model’s input data prototype, and predicting from a remote API endpoint. The vetiver package is extensible, with generics that can support many kinds of models. For an example of how to use and extend the vetiver package, see deploytidymodels.

Installation

You can install the released version of vetiver from CRAN with:

install.packages("vetiver") ## not yet

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("tidymodels/vetiver")

Example

A vetiver_model() object collects the information needed to store, version, and deploy a trained model.

You can version and share your model by choosing a pins “board” for it, including a local folder, RStudio Connect, Amazon S3, and more.

library(vetiver)
library(pins)

model_board <- board_temp()
cars_lm <- lm(mpg ~ ., data = mtcars)
v <- vetiver_model(cars_lm, "cars_linear", model_board)
v
#> 
#> ── cars_linear ─ <butchered_lm> model for deployment 
#> An OLS linear regression model using 10 features

When you use vetiver_pin_write(), you store and version your deployable, trained model object.

vetiver_pin_write(v)
#> Creating new version '20211007T203721Z-522c5'
#> Writing to pin 'cars_linear'

You can deploy your pinned vetiver() object via a Plumber API, which can be hosted in a variety of ways.

library(plumber)
pr() %>%
  vetiver_pr_predict(v) %>%
  pr_run(port = 8088)

Make predictions with your deployed model at its endpoint and new data.

endpoint <- vetiver_endpoint("http://127.0.0.1:8088/predict")
predict(endpoint, mtcars[4:7, -1])
#> # A tibble: 4 x 1
#>   .pred
#>   <dbl>
#> 1  21.2
#> 2  17.7
#> 3  20.4
#> 4  14.4

Contributing

This project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

  • For questions and discussions about modeling packages, modeling, and machine learning, please post on RStudio Community.

  • If you think you have encountered a bug, please submit an issue.

  • Either way, learn how to create and share a reprex (a minimal, reproducible example), to clearly communicate about your code.