我是python,PMML和augustus的新手,所以这个问题有点新手。我有一个PMML文件,我希望在每次新的数据迭代后得分。我必须使用Python和Augustus才能完成这个练习。我读过一些值得一提的各种文章,因为它们很好。
(http://augustusdocs.appspot.com/docs/v06/model_abstraction/augustus_and_pmml.html, http://augustus.googlecode.com/svn-history/r191/trunk/augustus/modellib/regression/producer/Producer.py)
我已经阅读了奥古斯都文档相关的评分,以了解它是如何工作的,但我无法解决这个问题。
使用R中的汽车数据生成样本PMML文件,其中“dist”是相关的,“speed”是独立变量。现在,每当我从等式中获得速度数据时,我想每次都预测dist(这是dist = -17.5790948905109 + speed * 3.93240875912408)。我知道它可以很容易地在R中使用预测功能完成,但问题是我在后端没有R并且只有python与augustus得分。任何帮助都非常感谢,并提前感谢。
样本PMML文件:
<?xml version="1.0"?>
<PMML version="4.1" xmlns="http://www.dmg.org/PMML-4_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dmg.org/PMML-4_1 http://www.dmg.org/v4-1/pmml-4-1.xsd">
<Header copyright="Copyright (c) 2013 user" description="Linear Regression Model">
<Extension name="user" value="user" extender="Rattle/PMML"/>
<Application name="Rattle/PMML" version="1.4"/>
<Timestamp>2013-11-07 09:24:06</Timestamp>
</Header>
<DataDictionary numberOfFields="2">
<DataField name="dist" optype="continuous" dataType="double"/>
<DataField name="speed" optype="continuous" dataType="double"/>
</DataDictionary>
<RegressionModel modelName="Linear_Regression_Model" functionName="regression" algorithmName="least squares">
<MiningSchema>
<MiningField name="dist" usageType="predicted"/>
<MiningField name="speed" usageType="active"/>
</MiningSchema>
<Output>
<OutputField name="Predicted_dist" feature="predictedValue"/>
</Output>
<RegressionTable intercept="-17.5790948905109">
<NumericPredictor name="speed" exponent="1" coefficient="3.93240875912408"/>
</RegressionTable>
</RegressionModel>
</PMML>
答案 0 :(得分:1)
您可以使用PyPMML在Python中为PMML模型评分,例如:
from pypmml import Model
model = Model.fromString('''<?xml version="1.0"?>
<PMML version="4.1" xmlns="http://www.dmg.org/PMML-4_1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dmg.org/PMML-4_1 http://www.dmg.org/v4-1/pmml-4-1.xsd">
<Header copyright="Copyright (c) 2013 user" description="Linear Regression Model">
<Extension name="user" value="user" extender="Rattle/PMML"/>
<Application name="Rattle/PMML" version="1.4"/>
<Timestamp>2013-11-07 09:24:06</Timestamp>
</Header>
<DataDictionary numberOfFields="2">
<DataField name="dist" optype="continuous" dataType="double"/>
<DataField name="speed" optype="continuous" dataType="double"/>
</DataDictionary>
<RegressionModel modelName="Linear_Regression_Model" functionName="regression" algorithmName="least squares">
<MiningSchema>
<MiningField name="dist" usageType="predicted"/>
<MiningField name="speed" usageType="active"/>
</MiningSchema>
<Output>
<OutputField name="Predicted_dist" feature="predictedValue"/>
</Output>
<RegressionTable intercept="-17.5790948905109">
<NumericPredictor name="speed" exponent="1" coefficient="3.93240875912408"/>
</RegressionTable>
</RegressionModel>
</PMML>''')
result = model.predict({'speed': 1.0})
结果是带有Predicted_dist的字典:
{'Predicted_dist': -13.646686131386819}