Convert PMML - Model (Artificial Neural Network) to Java Code

大兔子大兔子 提交于 2019-12-09 21:57:53

问题


I have a PMML file of a trained Artificial Neural Network (ANN). I would like to create a Java method which simply takes in the inputs and returns the targeted value.

This seems pretty easy, but I do not know how realize it.

The PMML Version = 3.0

Update: 24.05.2013

I tried to use the jpmml Java API.

This is how I have done:

(1) Downloaded via Maven Central Repository (link) three .Jar files:

  • pmml-manager-1.0.2.jar
  • pmml-model-1.0.2.jar
  • pmml-evaluator-1.0.2.jar

(2) Used eclipse to "configure Build path" and added those three external .Jar's

(3) Import my PMML-File named "text.xml" ( an artificial neural network (ANN)) PMML version="3.0"

(4) Tried to run an example "TreeModelTraversalExample.java" provided by the jpmml-project

Obviously it did not work for some reasons:

  • the mentioned example is not for ANN's. How to rewrite it?
  • my PMML-file is in XML-format. Is it the right format?
  • I do not know how to handle or to add Java API's. Should I even add those by "configure build path" in eclipse?

Obvious fact #2, I have no clue what I do :-)

Thanks again and kindest regards.

Stefan


回答1:


JPMML should be able to handle PMML 3.X and newer versions of NeuralNetwork models without problem. Moreover, it should be able to handle all the normalization and denormalization transformations that may accompany such models.

I could use a clarification that why are you interested in converting PMML models to Java code in the first place. This complicates the whole matter a lot and it doesn't add any value. The JPMML library itself is rather compact and has minimal external dependencies (at the moment of writing this, it only depends on commons-math). There shouldn't be much difference performance-wise. You can reasonably expect to obtain up to 10'000 scorings/sec on a modern desktop computer.

The JPMML codebase has recently moved to GitHub: http://github.com/jpmml/jpmml

Fellow coders in Turn Inc. have forked this codebase and are implementing PMML-to-Java translation (see top-level module "pmml-translation") for selected model types: https://github.com/turn/jpmml

At the moment I recommend you to check out the Openscoring project (uses JPMML internally): http://www.openscoring.org

Then, you could try the following:

  1. Deploy your XML file using the HTTP PUT method.
  2. Get your model summary information using the HTTP GET method. If the request succeeds (as opposed to failing with an HTTP status 500 error code) then your model is well supported.
  3. Execute the model either in single prediction mode or batch prediction mode using the HTTP POST method. Try sending larger batches to see if it meets your performance requirements.
  4. Undeploy the model using the HTTP DELETE method.

You can always try contacting project owners for more insight. I'm sure they are nice people.




回答2:


Another approach would be to use the Cascading API. There's a library called "Pattern" for Cascading, which translates PMML models into Cascading apps in Java. https://github.com/Cascading/pattern

Generally those are for Hadoop jobs; however, if you use the "local mode" flow planner in Cascading, it can be built as a JAR file to include with some other Java app.

There is work in progress for ANN models. Check on the developer email list: https://groups.google.com/forum/?fromgroups#!forum/pattern-user




回答3:


I think this might do what you need. It is an open source library that claims to be able to read and evaluate pmml neural networks. I have not tried it.

https://code.google.com/p/jpmml/



来源:https://stackoverflow.com/questions/16687649/convert-pmml-model-artificial-neural-network-to-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!