RapidMiner

Scoring a whole CSV file with a POST REST API call to Rapidminer Server

by Moderator ‎03-27-2017 08:15 AM - edited ‎03-31-2017 09:19 AM

This article deals with comma delimited data and CSV files.

 

For JSON, please look at:

http://community.rapidminer.com/t5/RapidMiner-Server-Knowledge-Base/Sending-JSON-data-to-a-Rapidmine...

For XML:

http://community.rapidminer.com/t5/RapidMiner-Server-Knowledge-Base/How-to-send-XML-data-to-a-Rapidm...

 

There is plenty of documentation on deploying a process as a service and on making GET calls through a browser to that service to get the scoring for a particular example / case / record.

 

When we want to sent a whole list of records to the server to get scored; we need a POST call. We can send commma delimited data through a .csv file.

 

Before we get started on this, it may be a bit daunting finding out how to do a POST call because it is not as simple as passing a single value through a web browser and a lot of articles out there approach making POST calls through programming languages. We will use cURL, a command line tool for sending and receiving files through URL syntax. It has many parameters but we only need two for now, further details can be found by typing "curl -h" in the command line or through https://en.wikipedia.org/wiki/CURL

 

Let us get started with a very simple process which trains a decision tree to classify customers. It is meant to be able to predict the "Response" attribute.

 

daily demo.png

A sample of the data is as follows:

daily demo data.png

 

For deployment, we have another process which imports the model built above on the data we have with known responses and applies it to data with unknown responses.

 

daily demo data.png

 

Please note how the "Read CSV" operator is connected to the imput port of the process canvas. This is so that it can receive data through the POST upload from the service we are going to create. This operator is not currently pointed to any file.

 

Before we create the service, bear in mind that the data we are going to pass for scoring does not have values in the response attribute, those values are going to be predicted.

 

daily demo data no response.png

 

Let us now create the service in Rapidminer Server:

 

create service.png

 

There are no special parameters or macros, as long as it points to the correct process for deployment. We then test the service to get the URL which, in this case, is:

http://RMUK-KBONIKOS:8080/api/rest/process/POSTtest?

 

We can use curl from the command line, which in Windows can be started from the Start menu by typing "cmd" and then we can enter the follwoing curl command:

 

curl --user admin --upload-file C:\test.csv http://RMUK-KBONIKOS:8080/api/rest/process/POSTtest?

 

The user in this case is "admin" and the file is test.csv and is saved in the C: drive, the path for the file can change. When this is executed, you will be asked for your password for the user and then you should get a list of scored records in XML in this case, this depends on the output format chosen when defining the service.

result.png

 

With the above help, you should be able to create a process and expose it as a service in Rapidminer Server and then test that is is able to receive files through a POST upload and score and return the output.