How to deploy an R XGboost model in UbiOps

Imagine this, you have just created a trained machine learning model or written an algorithm in R, and now you are looking for ways to put that code into practice. Well, you have come to the right place. UbiOps is a SaaS service that lets you make your data science application a reality and supports both R and Python code. This article will show you the most important steps to deploy an R XGboost deployment using the client library.

1. Use case

The use case that will be used for this article is as follows: because the house prices continue to rise, a model that would predict house prices may come in handy. The model is written in R and built using the R XGboost extension.

2. Script walkthrough and instructions

Below are the most important steps on how to create a deployment using the client library of UbiOps. The steps shown in this article are as follows:  (1) connect to the UbiOps environment, (2) create the R deployment, and (3) upload the deployment package to UbiOps.  If you want to see the full R script, please check out this link.

Deployment overview

The deployment is defined as follows:
NameInputOutput
r-xgboost-deploymentInput_data: Blob (file)Prediction: Blob (file)
Table 1: deployment overview
The code shown below is the code required to create the deployment.

Connect to the UbiOps environment (1)

Sys.setenv("UBIOPS_PROJECT" = "INSERT_YOUR_PROJECT_NAME_HERE")

Sys.setenv("UBIOPS_API_TOKEN" = "INSERT_YOUR_TOKEN_HERE")

Sys.setenv(UBIOPS_API_URL = "https://api.ubiops.com/v2.1")

DEPLOYMENT_NAME <- "r-xgboost-deployment"
DEPLOYMENT_VERSION <- "v1"

result <- service_status()
result

Create the deployment (2)

deployment <- list(

  name = DEPLOYMENT_NAME,

  description = "r-xgboost-deployment.",

  input_type = "structured",

  output_type = "structured",

  input_fields = list(

    list(name = "input_data", data_type = "blob")

  ),
  output_fields = list(

    list(name = "prediction", data_type = "blob")

  ),

  labels = list(demo = "r-xgboost-deployment")
)
result <- deployments_create(data = deployment)
result

Upload the deployment to UbiOps (3)

result <- revisions_file_upload(

  deployment.name = DEPLOYMENT_NAME,

  version = DEPLOYMENT_VERSION,

  file = r_xgboost_recipe_zip

)

build.id <- result$build

result

status <- "queued"

while(status != "success" && status != "failed") {

  result <- builds_get(

    deployment.name = DEPLOYMENT_NAME,

    version = DEPLOYMENT_VERSION,

    build.id = build.id

  )

  status <- result$status

  Sys.sleep(2)

}

print(status)

result <- deployment_versions_get(

  deployment.name = DEPLOYMENT_NAME,

  version = DEPLOYMENT_VERSION

)

result$status
After everything has finished building, requests can be made to the deployment.  Figure 1: request result Looks like the deployment is working perfectly!

3. Wrap up

And that is all it takes to create an R XGboost deployment on UbiOps! We hope that this helps you in your day-to-day projects. If you want to try out UbiOps, please visit app.ubiops.com/sign-up , where you can make an account and start deploying your model for free. For any questions or suggestions please join the UbiOps community slack channel or contact our customer support.

Download the Rscript here.

Latest news

Turn your AI & ML models into powerful services with UbiOps