How to score a linear model using PMML file and Augustus on Python

白昼怎懂夜的黑 提交于 2019-12-04 15:16:54

You could use PyPMML to score the PMML model in Python, for example:

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})

The result is a dict with Predicted_dist:

{'Predicted_dist': -13.646686131386819}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!