Apply PMML predictor model in python

2020-06-17 13:22发布

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

3条回答
Animai°情兽
2楼-- · 2020-06-17 14:15

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

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-06-17 14:17

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

查看更多
我想做一个坏孩纸
4楼-- · 2020-06-17 14:18

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

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

查看更多
登录 后发表回答