2014-06-20 5 views
2

간단한 PMML 파일을 가지고 있는데 점수 서버에 PUT을 보내고 싶습니다. 그것은 중요하지만 난 Openscoring PMML 득점 서버를 사용하고Python을 사용하여 PMML 넣기

<?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> 

확실하지 않음 것을 :

여기
curl -X PUT --data-binary @DecisionTreeIris.pmml -H "Content-type: text/xml" http://localhost:8080/openscoring/model/DecisionTreeIris 

가 PMML 파일입니다 : 여기에 curl 호출입니다.

+0

답변을 얻은 방법을 게시 할 수 있습니까? – Dan

답변

1

Kenneth Reitz (GitHubDocs)의 요청 라이브러리를 사용하는 것이 좋습니다.

특히, 파일을 POST하는 방법은 example입니다. 그것을 사용하여 필요한 것을 구성하십시오.

난 그냥 여기에 있으리라 믿고있어하지만 난 다음을 시도 할이 :

import requests 

url = 'http://localhost:8080/openscoring/model/DecisionTreeIris' 
files = {'file': open('/path/to/file/DecisionTreeIris.pmml', 'rb')} 

response = requests.post(url, files=files) 

당신은 또한 당신이 필요로하는 헤더 또는 다른 어떤을 설정할 수 있습니다. 요청은 사용하기 쉽고 파이썬 공동체에 이익이됩니다. 설명서가 우수하며 대개 Google/Bing/DuckDuckGo 검색을 통해 예제를 쉽게 찾을 수 있습니다.

도움이 되었기를 바랍니다.