Title: | R Binder for the Yhat API |
---|---|
Description: | Deploy, maintain, and invoke models via the Yhat REST API. |
Authors: | Greg Lamp <[email protected]>, Stevie Smith <[email protected]>, Ross Kippenbrock <[email protected]> |
Maintainer: | Greg Lamp <[email protected]> |
License: | FreeBSD |
Version: | 0.15.1 |
Built: | 2025-03-12 05:44:59 UTC |
Source: | https://github.com/yhat/yhatr |
Private function that adds a package to the list of dependencies that will be installed on the ScienceOps server
add.dependency(name, importName, src, version, install)
add.dependency(name, importName, src, version, install)
name |
name of the package to be installed |
importName |
name under which the package is imported (for a github package, this may be different from the name used to install it) |
src |
source that the package is installed from (CRAN or github) |
version |
version of the package |
install |
whether or not the package should be installed in the model image |
Private function for catpuring the source code of model
capture.src(funcs, capture.model.require = TRUE)
capture.src(funcs, capture.model.require = TRUE)
funcs |
functions to capture, defaults to required yhat model functions |
capture.model.require |
flag to capture the model.require function |
Checks dependencies and makes sure all are installed.
check.dependencies()
check.dependencies()
Private function for checking the size of the user's image.
check.image.size()
check.image.size()
Private predicate function that checks if the protocol of a url is https.
is.https(x)
is.https(x)
x |
is a url string |
Private function that generates a model.require function based on the libraries that have been imported in this session.
set.model.require()
set.model.require()
This function will deploy your batch model to the yhat servers
yhat.batchDeploy(job_name, confirm = TRUE)
yhat.batchDeploy(job_name, confirm = TRUE)
job_name |
name of batch job |
confirm |
boolean indicating whether to prompt before deploying |
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) yhat.batch <- function() { name <- "ross" greeting <- paste("Hello", name) print(greeting) } ## Not run: yhat.batchDeploy("helloworld") ## End(Not run)
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) yhat.batch <- function() { name <- "ross" greeting <- paste("Hello", name) print(greeting) } ## Not run: yhat.batchDeploy("helloworld") ## End(Not run)
This function takes model.transform and model.predict and creates
a model on Yhat's servers which can be called from any programming language
via Yhat's REST API (see yhat.predict
).
yhat.deploy(model_name, packages = c(), confirm = TRUE, custom_image = NULL)
yhat.deploy(model_name, packages = c(), confirm = TRUE, custom_image = NULL)
model_name |
name of your model |
packages |
list of packages to install using apt-get |
confirm |
boolean indicating whether to prompt before deploying |
custom_image |
name of the image you'd like your model to use |
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) iris$Sepal.Width_sq <- iris$Sepal.Width^2 fit <- glm(I(Species)=="virginica" ~ ., data=iris) model.require <- function() { # require("randomForest") } model.transform <- function(df) { df$Sepal.Width_sq <- df$Sepal.Width^2 df } model.predict <- function(df) { data.frame("prediction"=predict(fit, df, type="response")) } ## Not run: yhat.deploy("irisModel") yhat.deploy("irisModelCustomImage", custom_image="myImage:latest") ## End(Not run)
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) iris$Sepal.Width_sq <- iris$Sepal.Width^2 fit <- glm(I(Species)=="virginica" ~ ., data=iris) model.require <- function() { # require("randomForest") } model.transform <- function(df) { df$Sepal.Width_sq <- df$Sepal.Width^2 df } model.predict <- function(df) { data.frame("prediction"=predict(fit, df, type="response")) } ## Not run: yhat.deploy("irisModel") yhat.deploy("irisModelCustomImage", custom_image="myImage:latest") ## End(Not run)
Private function for performing a GET request
yhat.get(endpoint, query = c())
yhat.get(endpoint, query = c())
endpoint |
/path for REST request |
query |
url parameters for request |
Import one or more libraries and add them to the Yhat model's dependency list
yhat.library(name, src = "CRAN", version = NULL, user = NULL, install = TRUE)
yhat.library(name, src = "CRAN", version = NULL, user = NULL, install = TRUE)
name |
name of the package to be added |
src |
source from which the package will be installed on ScienceOps (github or CRAN) |
version |
version of the package to be added |
user |
Github username associated with the package |
install |
Whether the package should also be installed into the model on the ScienceOps server; this is typically set to False when the package has already been added to the ScienceOps base image. |
## Not run: yhat.library("MASS") yhat.library(c("wesanderson", "stringr")) yhat.library("cats", src="github", user="hilaryparker") yhat.library("hilaryparker/cats") yhat.library("my_proprietary_package", install=FALSE) ## End(Not run)
## Not run: yhat.library("MASS") yhat.library(c("wesanderson", "stringr")) yhat.library("cats", src="github", user="hilaryparker") yhat.library("hilaryparker/cats") yhat.library("my_proprietary_package", install=FALSE) ## End(Not run)
List all object names which are dependencies of 'model.transform' and 'model.predict' or 'yhat.batch' if this is a batch mode deploy
yhat.ls(batchMode = FALSE)
yhat.ls(batchMode = FALSE)
batchMode |
boolean to capture yhat.batch code for a batch job |
Private function for performing a POST request
yhat.post(endpoint, query = c(), data, silent = TRUE, bulk = FALSE)
yhat.post(endpoint, query = c(), data, silent = TRUE, bulk = FALSE)
endpoint |
/path for REST request |
query |
url parameters for request |
data |
payload to be converted to raw JSON |
silent |
should output of url to console be silenced?
Default is |
bulk |
is this a bulk style request? Default is |
This function calls Yhat's REST API and returns a response formatted as a data frame.
yhat.predict(model_name, data, model_owner, raw_input = FALSE, silent = TRUE)
yhat.predict(model_name, data, model_owner, raw_input = FALSE, silent = TRUE)
model_name |
the name of the model you want to call |
data |
input data for the model |
model_owner |
the owner of the model [optional] |
raw_input |
when true, incoming data will NOT be coerced into data.frame |
silent |
should output of url to console (via |
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) ## Not run: yhat.predict("irisModel", iris) ## End(Not run)
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) ## Not run: yhat.predict("irisModel", iris) ## End(Not run)
This function calls Yhat's bulk API and returns a response formatted as a data frame.
yhat.predict_bulk(model_name, data, model_owner, raw_input = FALSE, silent = TRUE)
yhat.predict_bulk(model_name, data, model_owner, raw_input = FALSE, silent = TRUE)
model_name |
the name of the model you want to call |
data |
input rows of data to be scored |
model_owner |
the owner of the model [optional] |
raw_input |
when true, incoming data will NOT be coerced into data.frame |
silent |
should output of url to console (via |
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) ## Not run: yhat.predict_bulk("irisModel", iris) ## End(Not run)
yhat.config <- c( username = "your username", apikey = "your apikey", env = "http://sandbox.yhathq.com/" ) ## Not run: yhat.predict_bulk("irisModel", iris) ## End(Not run)
Calls Yhat's REST API and returns a JSON document containing both the prediction and associated metadata.
yhat.predict_raw(model_name, data, model_owner, raw_input = FALSE, silent = TRUE, bulk = FALSE)
yhat.predict_raw(model_name, data, model_owner, raw_input = FALSE, silent = TRUE, bulk = FALSE)
model_name |
the name of the model you want to call |
data |
input data for the model |
model_owner |
the owner of the model [optional] |
raw_input |
when true, incoming data will NOT be coerced into data.frame |
silent |
should output of url to console (via |
bulk |
should the bulk api be used Default is |
yhat.config <- c( username = "your username", apikey = "your apikey" ) ## Not run: yhat.predict_raw("irisModel", iris) ## End(Not run)
yhat.config <- c( username = "your username", apikey = "your apikey" ) ## Not run: yhat.predict_raw("irisModel", iris) ## End(Not run)
Private function for recursively looking for variables
yhat.spider.block(block, defined.vars = c())
yhat.spider.block(block, defined.vars = c())
block |
code block to spider |
defined.vars |
variables which have already been defined within the scope of the block. e.g. function argument |
Private function for spidering function source code
yhat.spider.func(func.name)
yhat.spider.func(func.name)
func.name |
name of function you want to spider |
Removes a library from the Yhat model's dependency list
yhat.unload(name)
yhat.unload(name)
name |
of the package to be removed |
## Not run: yhat.unload("wesanderson") ## End(Not run)
## Not run: yhat.unload("wesanderson") ## End(Not run)
Private function for verifying username and apikey
yhat.verify()
yhat.verify()