Click here to Skip to main content
15,886,518 members
Articles / Programming Languages / R

How to Pass and consume Azure ML Input Web service Parameters to R modules in Azure ML

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
6 Mar 2018CPOL4 min read 9K   1  
The article aims to explain the process of passing input web service parameters to Execute R Script module, in Azure Machine Learning.

Execute R Script Module in Azure ML

Azure Machine learning platform allows users to extend the functionality of their experiments by means of using R code scripts. This can be achieved using the ‘Execute R Script’ module of Azure ML. The module has three inputs and two outputs. It can accept three inputs, viz, two (different) datasets and one script bundle inputs. The input datasets provide the data needed within the R script processing while the script bundle input makes available the R libraries required by the R code for processing. The required R libraries are uploaded into the Azure ML platform as zip files and then passed on to the module as an input. For more details about this, please follow this blog post.

Image 1

The datasets which are provided to the R script as input are consumed as a data frame within the ‘Execute R script’ module and are accessed using the command

  • dataset1 <- maml.mapInputPort(1)    # for accessing first Input Port
  • dataset2 <- maml.mapInputPort(2)    # for accessing second Input Port

The two output ports of Execute R Script module are: Result Dataset and R device. Using the first output port, Result dataset used can output the resultant contents, after execution of the R script, as a rectangular table by means of the maml.mapOutputPort() command.

R device output of the module contains the messages and graphic output produced as a result of R script execution.

Azure ML Web Services

Azure ML experiments are deployed as web services so that these can be utilized by other applications and programs, in order to make predications. These experiments can either be a model or some machine learning workflows. The experiments are published and deployed as RESTFUL web services so that these can be consumed by different platforms and applications either in real time or batch mode.

Azure ML web services can managed using Azure API Management. For more details about the Azure API management, please follow this link.

Azure ML Web Services Parameters

Whenever Azure ML experiments are published, deployed and consumed as a web service, in general, there is a requirement to pass on and receive the data, to and from the experiments. This is facilitated by Web Service Parameters. These parameters can be associated with one or more modules of Azure ML experiment and when this web service is accessed by any external application or program, consumer of the web service needs to provide the values for such input parameters and also collect the data provided as an output using the output parameters. The parameters can be configured as mandatory or optional.

Scenario

Now with an understanding of Execute R script, Azure ML web service and its parameters, consider a scenario in which it is required to pass some input values as data from an external application, calling the Azure ML web service (of an experiment), into the ‘Execute R Script’ module of the experiment. Let’s imagine a use case in which there is a need to pass some value to R code, residing in the Execute R script module, via web service parameter. This becomes a problem since the Azure ML platform does not allow to configure a user defined parameter for web service. What is the solution to this problem? There are two ways to address this situation; either develop a Custom R module or follow an alternative approach. Here, we will discuss the alternative approach.

In order to pass input values as web service parameter to R script, take the source dataset (containing the data to processes) and then augment an ‘Add Columns’ module in to Azure ML canvas. Join the output of source dataset to the first input of ‘Add Columns’ module.

As a next step, prepare one .csv file with a single column (and its header). Upload this .csv file into the Azure ML platform as a dataset and then add this dataset into the current experiment canvas.

Now, add this csv dataset and a web service input parameter, with the Add column module’s 2nd input (both entities on the same input port).

Image 2

In this way, the Add column module will add one more column in the source data set with the column name as specified in the csv file and the values of this column will be filled with the value passed as an input data while calling the web service. The resultant dataset at the input port of the Add column module will contain an additional column for which the value will be filled with the data value passed as an input when the web service call is made. This resultant dataset can be fed into the ‘Execute R script’ module and the web service input parameter value can be accessed within the R code / script as:

  • Dataset1 <- maml.mapInputPort(1)
  • wsinput <- Dataset1$<<name of the column containing the web service input parameter value >>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --