Apply PMML predictor model in python
Asked Answered
I

3

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

Iselaisenberg answered 22/3, 2013 at 18:29 Comment(5)
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 (help to use it). (I have no experience with Augustus.)Spillway
@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.Iselaisenberg
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.Spillway
@GáborBakos, I'm waiting for someone with Augustus expertice to know best steps to deploy it.Iselaisenberg
ok, have you check the documentation I linked? It does not seem to be too complicated.Spillway
I
2

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

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

Iselaisenberg answered 24/3, 2013 at 15:13 Comment(0)
S
2

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

Snowplow answered 5/6, 2013 at 18:21 Comment(1)
Does Augustus support Association Model? Because I am getting AssociationModel has not been implemented yet error.Clayson
G
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

Gordon answered 25/7, 2019 at 2:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.