简体   繁体   English

在python中应用PMML预测器模型

[英]Apply PMML predictor model in python

Knime has generated for me a PMML model. Knime为我生成了一个PMML模型。 At this time I want to apply this model to a python process. 这时我想将这个模型应用于python进程。 What is the right way to do this? 这样做的正确方法是什么?

More in depth: I develop a django student attendance system . 更深入:我开发了一个django学生出勤系统 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. 这就是PMML的用武之地.Knime已经生成了一个预测学生出勤率的PMML模型。 Also, thanks to django for being so productive that I time for this great work ;) 另外,感谢django如此高效,以至于我为这项伟大的工作留出时间;)

在此输入图像描述

Finally I have wrote my own code. 最后我写了自己的代码。 Be free to contribute or fork it: 可以自由贡献或分叉:

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

使用Python对PMML模型进行评分的Augustus代码位于https://code.google.com/p/augustus/

You could use PyPMML to apply PMML in Python, for example: 您可以使用PyPMML在Python中应用PMML,例如:

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. 数据可以是Pandas的dict,json,Series或DataFrame。

If you use PMML in PySpark, you could use PyPMML-Spark , for example: 如果你在PySpark中使用PMML,你可以使用PyPMML-Spark ,例如:

from pypmml_spark import ScoreModel

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

The df is a DataFrame of PySpark. df是PySpark的DataFrame。

For more info about other PMML libraries, be free to see: https://github.com/autodeployai 有关其他PMML库的更多信息,请访问: https//github.com/autodeployai

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM