6

Knime has generated for me a PMML model. At this time I want to apply this model to a python process. What is the right way to do this?

More in depth: I develop a django student attendance system. The application is already so mature that I have time to implement the 'I'm feeling lucky' button to automatically fill an attendance form. Here is where PMML comes in. Knime has generated a PMML model that predicts student attendance. Also, thanks to django for being so productive that I time for this great work ;)

enter image description here

Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
dani herrera
  • 48,760
  • 8
  • 117
  • 177
  • What is exactly the problem? You can export the PMML model from KNIME with PMML Writer. One of the PMML processing libs in Python is [Augustus](https://code.google.com/p/augustus/) ([help to use it](http://174.129.21.118/augustus/Primer/html/basic-walkthrough-gaslog-consumer.html#run-augustus-as-a-model-consumer)). (I have no experience with Augustus.) – Gábor Bakos Mar 23 '13 at 13:39
  • @GáborBakos, I have not experience with Augustus. I will like to call a simple prediction function: `prediction = please_predict( model.xml, dict )` . I this that I will code my self a function to do it, it is not complex for a decision tree. – dani herrera Mar 23 '13 at 18:01
  • It seems it (Augustus) can perform easy prediction, although you have to make a few transformations (convert to xml, convert back from xml). You can hide this to such a detail behind the function you provided. – Gábor Bakos Mar 23 '13 at 20:17
  • @GáborBakos, I'm waiting for someone with Augustus expertice to know best steps to deploy it. – dani herrera Mar 23 '13 at 20:52
  • ok, have you check the documentation I linked? It does not seem to be too complicated. – Gábor Bakos Mar 23 '13 at 20:53

3 Answers3

2

Finally I have wrote my own code. Be free to contribute or fork it:

https://github.com/ctrl-alt-d/lightpmmlpredictor

dani herrera
  • 48,760
  • 8
  • 117
  • 177
2

The code for Augustus, to score PMML models in Python, is at https://code.google.com/p/augustus/

Paco
  • 602
  • 1
  • 9
  • 19
2

You could use PyPMML to apply PMML in Python, for example:

from pypmml import Model

model = Model.fromFile('the/pmml/file/path')
result = model.predict(data)

The data could be dict, json, Series or DataFrame of Pandas.

If you use PMML in PySpark, you could use PyPMML-Spark, for example:

from pypmml_spark import ScoreModel

model = ScoreModel.fromFile('the/pmml/file/path')
score_df = model.transform(df)

The df is a DataFrame of PySpark.

For more info about other PMML libraries, be free to see: https://github.com/autodeployai

PredictFuture
  • 216
  • 2
  • 6