Site icon R-bloggers

OpenScoring: Open Source Scoring of PMML Models via REST

[This article was first published on Advanced Analytics Blog by Scott Mutchler, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The other day I stumbled accross an amazing PMML model API called jpmml.  It’s written in Java and supports PMML 4.1 (and older).  Neural networks, random forests, regression and trees PMML models can be consumed and used for scoring.

I decided to write a REST interface that wraps the jpmml engine.  This allows remote clients, written in just about any language, to have a simple interface to “cloud” scoring.

You can develop your predictive models in R, export them to PMML and score the models directly from client applications.  I’m a big fan of Rattle for the first two steps.

OpenScoring can be dowloaded from http://code.google.com/p/openscoring/.

To install the OpenScoring web application in Tomcat, copy the OpenScoring.war file to the $TOMCAT_HOME\webapps directory.

To invoke the scoring service, you perform an HTTP POST to http://localhost:8080/OpenScoring/Scoring.  The format of the post is XML.  Here is a sample POST to score against a Neural Network PMML model using the well-known iris data set.

Here is the sample XML input:



The pmml_url element is a http, file or ftp URL that points to the PMML XML file.  The csv_input_rows element contains the records to score.  The rows are comma separated values with pipe delimited rows.

Here is the response XML:



It’s a bit hard to read but the response contains all the input data with an additional column $PREDICTED.  The $PREDICTED column contains the species prediction propensities.

There is also a Java API.  Here is sample code to call the REST scoring service from Java:

StringBuffer csvInputRows = new StringBuffer();
csvInputRows.append(
“sepal_length,sepal_width,petal_length,petal_width”)
.append(“\n”);
csvInputRows.append(“5.1,3.5,1.4,0.2”).append(“\n”);
csvInputRows.append(“7,3.2,4.7,1.4”).append(“\n”);
csvInputRows.append(“6.3,2.9,5.6,1.8”).append(“\n”);

ScoringRequest req = new ScoringRequest(
“http://localhost:8080/OpenScoring/Scoring”,
“http://www.dmg.org/pmml_examples/knime_pmml_examples/neural_network_iris.xml”,
null, // model name (null = default)
null, // user id for basic authentication
null, // password for basic authentication
csvInputRows.toString());

ScoringResponse res = ScoringClient.score(req);

System.out.println(res.getCsvOutputRows()); 

The output CSV in Excel is:



The software is currently in alpha release v0.1.   It’s distributed under a GPL v3 license.  

If you are interested in contributing to this software please feel free to join in!






To leave a comment for the author, please follow the link and comment on their blog: Advanced Analytics Blog by Scott Mutchler.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.