Code Monkey home page Code Monkey logo

deploytidymodels's Introduction

deploytidymodels

This repo is archived in favor of the vetiver package.

The goal of deploytidymodels is to provide fluent tooling to version, share, and deploy a trained model workflow using the vetiver framework. Functions handle both recording and checking the model’s input data prototype, and loading the packages needed for prediction.

Installation

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

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

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("juliasilge/deploytidymodels")

Example

You can use the tidymodels ecosystem to train a model, with a wide variety of preprocessing and model estimation options.

library(parsnip)
library(workflows)
data(Sacramento, package = "modeldata")

rf_spec <- rand_forest(mode = "regression")
rf_form <- price ~ type + sqft + beds + baths

rf_fit <- 
    workflow(rf_form, rf_spec) %>%
    fit(Sacramento)

You can version and share your model by pinning it, to a local folder, RStudio Connect, Amazon S3, and more.

library(deploytidymodels)
library(pins)

model_board <- board_temp()
m <- vetiver_model(rf_fit, "sacramento_rf", model_board)
vetiver_pin_write(m)
#> Creating new version '20211008T150541Z-21d32'
#> Writing to pin 'sacramento_rf'

You can deploy your pinned model via a Plumber API, which can be hosted in a variety of ways.

library(plumber)

pr() %>%
    vetiver_pr_predict(m) %>%
    pr_run(port = 8088)

Make predictions with your deployed model by creating an endpoint object:

endpoint <- vetiver_endpoint("http://127.0.0.1:8088/predict")
endpoint
#> 
#> ── A model API endpoint for prediction: 
#> http://127.0.0.1:8088/predict

A model API endpoint deployed with vetiver_pr_predict() will return predictions with appropriate new data.

library(tidyverse)
new_sac <- Sacramento %>% 
    slice_sample(n = 20) %>% 
    select(type, sqft, beds, baths)

predict(endpoint, new_sac)
#> # A tibble: 20 x 1
#>      .pred
#>      <dbl>
#>  1 165042.
#>  2 212461.
#>  3 119008.
#>  4 201752.
#>  5 223096.
#>  6 115696.
#>  7 191262.
#>  8 211706.
#>  9 259336.
#> 10 206826.
#> 11 234952.
#> 12 221993.
#> 13 204983.
#> 14 548052.
#> 15 151186.
#> 16 299365.
#> 17 213439.
#> 18 287993.
#> 19 272017.
#> 20 226629.

Contributing

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

deploytidymodels's People

Contributors

juliasilge avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.