在Python中应用PMML预测模型

6 投票
3 回答
9620 浏览
提问于 2025-04-17 20:00

Knime为我生成了一个PMML模型。现在我想把这个模型应用到一个Python的流程中。该怎么做才对呢?

更详细一点:我正在开发一个django学生考勤系统。这个应用已经发展得相当成熟,所以我有时间来实现一个“我感觉幸运”按钮,自动填写考勤表。这个时候PMML就派上用场了。Knime生成的PMML模型可以预测学生的考勤情况。此外,感谢django的高效,让我有时间做这个很棒的工作;)

enter image description here

3 个回答

2

你可以使用 PyPMML 在 Python 中应用 PMML,举个例子:

from pypmml import Model

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

数据可以是字典、json格式、Pandas的Series或者DataFrame。

如果你在 PySpark 中使用 PMML,可以使用 PyPMML-Spark,比如:

from pypmml_spark import ScoreModel

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

这里的 df 是 PySpark 的 DataFrame。

想了解更多关于其他 PMML 库的信息,可以随时查看: https://github.com/autodeployai

2

在这里,你可以找到用Python给PMML模型打分的Augustus代码,网址是 https://code.google.com/p/augustus/

2

最后我写了自己的代码。欢迎大家来贡献或者复制它:

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

撰写回答