How to deploy a pipeline in UbiOps, that is written in R code.

In a perfect world, every code would have a perfect input and output. Meaning that the gathered data would fit the model perfectly and no further data manipulation is needed. In the real world, however, after the data has been gathered it still needs cleaning, the data needs to be explored, model interference etcetera. Splitting these steps up into different codes, after which the input of one code is the output of another, allows for several benefits like reusability, scalability, and transparency.

After the pipeline has been deployed it is possible to make an express request to it, or a batch request and run it in the cloud. An express request takes a single data payload and keeps a connection open during processing, after which the result is returned immediately, this type of request is synchronous. A batch request is asynchronous and requires two API calls to send the data and retrieve the results. A batch request can take up to 250 data payloads simultaneously, for each of them a separate request_id is returned with which the results can be retrieved at a later time.

UbiOps also provides the ability to create different versions of the pipeline. All versions have the same input and output, but the deployed code package, programming language, memory allocation, and other settings can be different. It is also possible to add multiple deployment versions to the pipeline. Moreover, you can make a schedule for the requests, it is easy to execute your code at a configurable time interval. This could come in handy when your code does not depend on direct input data but instead connects to a data source inside the code.

This article will show you how to deploy an R pipeline, that chains two deployments together, the pipeline will predict house prices from this public dataset. The first deployment will explore and prepare the data for the second deployment, which will predict the prices of houses. If you want to see how to deploy a pipeline with Python code click here.

If you want to see how to chain R deployments with Python deployments, please click here

 

1. Use case

With the ever-rising house prices, a model that can predict the prices of houses using the previously mentioned dataset would be useful. Let’s develop a model that explores and prepares the data for a prediction model.

 

2. Script walkthrough and instructions

After the pipeline overview, the following steps to make a pipeline on UbiOps are shown:

Pipeline overview

 

DeploymentFunction
eda-deploymentExplore and prepare the data for the prediction deployment
prediction-deploymentPredict the house prices
Table 1: function overview

 

The visual presentation of the pipeline in the UbiOps looks like this:

 

Figure 1: pipeline overview

 

Whereby the following input and output fields are defined:

 

DeploymentInputoutput
eda-deploymentraw_dataclean_data
prediction-deploymentclean_dataprediction
Table 2: input and output overview

 

Below the following steps are shown:

 

  1. How to make a deployment
  2. How to make a pipeline
  3. How to turn that deployment into an object, which is the name for a deployment in a pipeline
  4. How to connect the objects

If you want to see the full script, please click here.

 

  1. Build the deployment

———————————————–

eda-deployment

deployment <- list(

 name = DEPLOYMENT_NAME1,

 description = "eda-prep-deployment",

 input_type = "structured",

 output_type = "structured",

 input_fields = list(

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

 ),
 output_fields = list(

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

  labels = list(demo = "eda-prep-deployment")

)

result <- deployments_create(data = deployment)

result
Prediction deployment
deployment <- list(

  name = DEPLOYMENT_NAME2,

 description = "prediction-deployment",

  input_type = "structured",

 output_type = "structured",

  input_fields = list(

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

 ),

  output_fields = list(

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

  ),

 labels = list(demo = "prediction-deployment")

)

result <- deployments_create(data = deployment)

result

 

 

  1. Make the pipeline

pipeline <- list(

    name = PIPELINE_NAME,

    description = "Pipeline that predics house prices",

   input_type = "structured",

    input_fields = list(

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

    ),

   output_type = "structured",

    output_fields = list(

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

    ),

   labels = list(demo = "r-pipeline")

)

result_pipe <- pipelines_create(data = pipeline)

result_pipe

pipeline_version <- list(

    version = PIPELINE_VERSION,

   request_retention_mode="none"  # We don"t need to store the requests in this de

)

result <- pipeline_versions_create(

   pipeline.name = PIPELINE_NAME,

   data = pipeline_version

)

result

 

 

  1. Add the deployments as objects to the pipeline

object <- list(

    name = DEPLOYMENT_NAME1,

    reference_name = DEPLOYMENT_NAME1,

   version = DEPLOYMENT_VERSION

)

result <- pipeline_version_objects_create(

    pipeline.name = PIPELINE_NAME,

    version = PIPELINE_VERSION,

   data = object

)

result

object <- list(

    name = DEPLOYMENT_NAME2,

    reference_name = DEPLOYMENT_NAME2,

    version = DEPLOYMENT_VERSION

)

result <- pipeline_version_objects_create(

   pipeline.name = PIPELINE_NAME,

    version = PIPELINE_VERSION,

   data = object

)

result

 

 

  1. Connect the components

attachment2 <- list(

   destination_name = DEPLOYMENT_NAME2,

    sources = list(

        list(

            source_name = DEPLOYMENT_NAME1,

            mapping = list(

               list(source_field_name = "clean_data", destination_field_name = "clean_data")

           )

       )

    )

)

result <- pipeline_version_object_attachments_create(

    pipeline.name = PIPELINE_NAME,

   version = PIPELINE_VERSION,

    data = attachment2

)

result

After everything has finished building, requests can be made to the pipeline by clicking the following button:

 

When a request is made, the following will be shown:

Fig 2: pipeline request result

3. Wrap up

That is all it takes to deploy a pipeline written in R on UbiOps! We hope that this will help you in your day-to-day projects. Are you interested in UbiOps? Why not make a free account on https://ubiops.com/, and start deploying your models today. If you have any questions, do not hesitate to contact us on our community slack channel, or contact our customer support.


Download the full Rscript here.

 

Latest news

Turn your AI & ML models into powerful services with UbiOps