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!
Very interesting thing - but trying the example you gave all results into an error 404 after deploying the war file in tomcat7. I use the Poster addin for Firefox for testing (https://addons.mozilla.org/de/firefox/addon/poster/). Any clues?
ReplyDeleteDid you type the URL exactly (case matters) as above?
ReplyDeletehttp://localhost:8080/OpenScoring/Scoring
404 is resource not found. This implies the WAR did not deploy and the context was not created or you used the wrong URL. Let me know what you find.
First, thanks for the fast reply. Yes the URL was exactly as above. I also checked the deployment of war-File. The catalina logfiles told me it was successfully done. The applications also appears at the tomcat management page. Looking at the unpacked war file it seems that the web.xml is missing, or?
Deletethanks in advance
OK, it now works perfectly. Therefore I had to do the following things:
Delete- download the sources
- import in eclipse
- change platform to jdk6
- change paths to the libraries (from Google docs to lib)
- drop oracle jdbc jar
- build war
This application is something I definitely will have an eye on.
Thanks so much! I made the same changes to the WAR and source bundles.
DeleteI think I've fixed the problems. The PMML file referenced in the example is only intermittantly available for some reason.
ReplyDeleteSee the new files and instructions for installing locally to Tomcat on the OpenScoring site. Let me know how it works for you.
I also fixed a bug with the error handling.