在 Python 中使用 PMML 模型

Use PMML models in Python

我在 Internet 上找到了很多与此相关的主题,但我找不到解决方案。

假设我想从 this examples list 下载任何 PMML 模型,并 运行 在 Python 中下载它们(最好是 Python 3)。有什么办法吗?

我正在寻找一种方法来导入部署在 Python 外部的 PMML 并将其导入以使用此语言。

经过一番研究,我找到了解决方案:the 'openscoring' library

使用起来很简单:

import subprocess
from openscoring import Openscoring
import numpy as np

p = subprocess.Popen('java -jar openscoring-server-executable-1.4.3.jar',
             shell=True)

os = Openscoring("http://localhost:8080/openscoring")

# Deploying a PMML document DecisionTreeIris.pmml as an Iris model:   
os.deployFile("Iris", "DecisionTreeIris.pmml")

# Evaluating the Iris model with a data record:
arguments = {
    "Sepal_Length" : 5.1,
    "Sepal_Width" : 3.5,
    "Petal_Length" : 1.4,
    "Petal_Width" : 0.2
}
result = os.evaluate("Iris", arguments)
print(result)

此returns目标变量在字典中的值。不再需要在 Python 之外使用 PMML 模型(您只需要 运行 使用 Java 服务器,这可以使用 Python 以及我在上面展示了)。

您可以使用 PyPMML 在 Python 中应用 PMML,例如:

from pypmml import Model

model = Model.fromFile('DecisionTreeIris.pmml')
result = model.predict({
    "Sepal_Length" : 5.1,
    "Sepal_Width" : 3.5,
    "Petal_Length" : 1.4,
    "Petal_Width" : 0.2
})

有关其他 PMML 库的更多信息,请免费查看: https://github.com/autodeployai