我是 python、PMML 和 augustus 的新手,所以这个问题有点新手。我有一个 PMML 文件,我想在每次新的数据迭代后从中评分。我必须使用 Python 和 Augustus 来完成这个练习。我读过各种文章,其中一些值得一提,因为它们很好。
(http://augustusdocs.appspot.com/docs/v06/model_abstraction/augustus_and_pmml.html 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 http://augustus.googlecode.com/svn-history/r191/trunk/augustus/modellib/regression/producer/Producer.py)
我已阅读与评分相关的奥古斯都文档以了解其工作原理,但我无法解决这个问题。
使用 R 中的汽车数据生成示例 PMML 文件,其中“距离”是因变量,“速度”是自变量。现在,每当我从方程中收到速度数据时,我想预测 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>
你可以使用PyPMML https://github.com/autodeployai/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}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)