json - Using Python to PUT PMML -
json - Using Python to PUT PMML -
i have simple pmml file put
scoring server. here curl
call:
curl -x set --data-binary @decisiontreeiris.pmml -h "content-type: text/xml" http://localhost:8080/openscoring/model/decisiontreeiris
here pmml file:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <pmml xmlns="http://www.dmg.org/pmml-4_1" version="4.1"> <header copyright="copyright (c) 2013 vfed" description="rpart decision tree model"> <extension extender="rattle/pmml" name="user" value="vfed"/> <application name="rattle/pmml" version="1.2.34r27"/> <timestamp>2013-05-15 22:02:28</timestamp> </header> <datadictionary numberoffields="5"> <datafield name="species" optype="categorical" datatype="string"> <value value="setosa"/> <value value="versicolor"/> <value value="virginica"/> </datafield> <datafield name="sepal.length" optype="continuous" datatype="double"/> <datafield name="sepal.width" optype="continuous" datatype="double"/> <datafield name="petal.length" optype="continuous" datatype="double"/> <datafield name="petal.width" optype="continuous" datatype="double"/> </datadictionary> <treemodel modelname="rpart_model" functionname="classification" algorithmname="rpart" missingvaluestrategy="defaultchild" splitcharacteristic="binarysplit"> <miningschema> <miningfield name="species" usagetype="predicted"/> <miningfield name="sepal.length" usagetype="active"/> <miningfield name="sepal.width" usagetype="active"/> <miningfield name="petal.length" usagetype="active"/> <miningfield name="petal.width" usagetype="active"/> </miningschema> <output> <outputfield name="predicted_species" optype="categorical" datatype="string" feature="predictedvalue"/> <outputfield name="probability_setosa" optype="continuous" datatype="double" feature="probability" value="setosa"/> <outputfield name="probability_versicolor" optype="continuous" datatype="double" feature="probability" value="versicolor"/> <outputfield name="probability_virginica" optype="continuous" datatype="double" feature="probability" value="virginica"/> <!-- custom output field --> <outputfield name="node_id" optype="categorical" datatype="string" feature="entityid"/> </output> <node id="1" score="setosa" recordcount="150.0" defaultchild="3"> <true/> <scoredistribution value="setosa" recordcount="50.0" confidence="0.333333333333333"/> <scoredistribution value="versicolor" recordcount="50.0" confidence="0.333333333333333"/> <scoredistribution value="virginica" recordcount="50.0" confidence="0.333333333333333"/> <node id="2" score="setosa" recordcount="50.0"> <compoundpredicate booleanoperator="surrogate"> <simplepredicate field="petal.length" operator="lessthan" value="2.45"/> <simplepredicate field="petal.width" operator="lessthan" value="0.8"/> <simplepredicate field="sepal.length" operator="lessthan" value="5.45"/> <simplepredicate field="sepal.width" operator="greaterorequal" value="3.35"/> </compoundpredicate> <scoredistribution value="setosa" recordcount="50.0" confidence="1.0"/> <scoredistribution value="versicolor" recordcount="0.0" confidence="0.0"/> <scoredistribution value="virginica" recordcount="0.0" confidence="0.0"/> </node> <node id="3" score="versicolor" recordcount="100.0" defaultchild="7"> <compoundpredicate booleanoperator="surrogate"> <simplepredicate field="petal.length" operator="greaterorequal" value="2.45"/> <simplepredicate field="petal.width" operator="greaterorequal" value="0.8"/> <simplepredicate field="sepal.length" operator="greaterorequal" value="5.45"/> <simplepredicate field="sepal.width" operator="lessthan" value="3.35"/> </compoundpredicate> <scoredistribution value="setosa" recordcount="0.0" confidence="0.0"/> <scoredistribution value="versicolor" recordcount="50.0" confidence="0.5"/> <scoredistribution value="virginica" recordcount="50.0" confidence="0.5"/> <node id="6" score="versicolor" recordcount="54.0"> <compoundpredicate booleanoperator="surrogate"> <simplepredicate field="petal.width" operator="lessthan" value="1.75"/> <simplepredicate field="petal.length" operator="lessthan" value="4.75"/> <simplepredicate field="sepal.length" operator="lessthan" value="6.15"/> <simplepredicate field="sepal.width" operator="lessthan" value="2.95"/> </compoundpredicate> <scoredistribution value="setosa" recordcount="0.0" confidence="0.0"/> <scoredistribution value="versicolor" recordcount="49.0" confidence="0.907407407407407"/> <scoredistribution value="virginica" recordcount="5.0" confidence="0.0925925925925926"/> </node> <node id="7" score="virginica" recordcount="46.0"> <compoundpredicate booleanoperator="surrogate"> <simplepredicate field="petal.width" operator="greaterorequal" value="1.75"/> <simplepredicate field="petal.length" operator="greaterorequal" value="4.75"/> <simplepredicate field="sepal.length" operator="greaterorequal" value="6.15"/> <simplepredicate field="sepal.width" operator="greaterorequal" value="2.95"/> </compoundpredicate> <scoredistribution value="setosa" recordcount="0.0" confidence="0.0"/> <scoredistribution value="versicolor" recordcount="1.0" confidence="0.0217391304347826"/> <scoredistribution value="virginica" recordcount="45.0" confidence="0.978260869565217"/> </node> </node> </node> </treemodel> </pmml>
not sure matters using openscoring pmml scoring server.
i'd recommend using requests library kenneth reitz (github , docs).
specifically, there's example on how post files. utilize build need.
i'm assuming here seek following:
import requests url = 'http://localhost:8080/openscoring/model/decisiontreeiris' files = {'file': open('/path/to/file/decisiontreeiris.pmml', 'rb')} response = requests.post(url, files=files)
you can set headers or else need. requests dead simple utilize , boon python community. documentation first-class , can find examples google/bing/duckduckgo search easily.
i hope helps!
python json rest python-3.x pmml
Comments
Post a Comment