2017-02-06 3 views
0

今日私のコードでpmmlモデルを読み込むためにJpmmlを使用しています。 '評価する'方法には長い時間がかかります。評価方法に時間がかかります - PMMLモデルJpmmlを使用

String modelPath = "...."; 
    ModelEvaluatorFactory factory = ModelEvaluatorFactory.newInstance(); 
    InputStream in = new ByteArrayInputStream(modelPath.getBytes("UTF-8")); 

    PMML pmmlModel = JAXBUtil.unmarshalPMML(new StreamSource(in)); 
    ModelEvaluator<?> evaluator = factory.newModelManager(pmmlModel); 
    List<FieldName> activeFields = evaluator.getActiveFields(); 

    Map<FieldName, FieldValue> defaultFeatures = new HashMap<>(); 

    //after filling the 'defaultFeatures' the line below takes long time 
    Map<FieldName, ?> results = evaluator.evaluate(defaultFeatures); 

PMML例:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
    <PMML xmlns="http://www.dmg.org/PMML-4_2" version="4.2"> 
    <Header> 
     <Application name="JPMML-SkLearn" version="1.0-SNAPSHOT"/> 
     <Timestamp>2017-01-22T14:18:05Z</Timestamp> 
    </Header> 
    <DataDictionary> 
     <DataField name="GENDER" optype="categorical" dataType="string"> 
      <Value value="0"/> 
      <Value value="1"/> 
     </DataField> 
     <DataField name="1GA_" optype="continuous" dataType="double"/> 
    //67000 rows of datafield 
    </DataDictionary> 
    <TransformationDictionary> 
     <DefineFunction name="logit" optype="continuous" dataType="double"> 
      <ParameterField name="value" optype="continuous" dataType="double"/> 
      <Apply function="/"> 
       <Constant dataType="double">1</Constant> 
       <Apply function="+"> 
        <Constant dataType="double">1</Constant> 
        <Apply function="exp"> 
         <Apply function="*"> 
          <Constant dataType="double">-1</Constant> 
          <FieldRef field="value"/> 
         </Apply> 
        </Apply> 
       </Apply> 
      </Apply> 
     </DefineFunction> 
    </TransformationDictionary> 
    <MiningModel functionName="classification"> 
     <MiningSchema> 
      <MiningField name="GENDER" usageType="target"/> 
      <MiningField name="1GA_"/> 
     //67000 rows of MiningField 
     </MiningSchema> 
     <Output> 
      <OutputField name="probability_0" feature="probability" value="0"/> 
      <OutputField name="probability_1" feature="probability" value="1"/> 
     </Output> 
     <LocalTransformations> 
      <DerivedField name="x1" optype="continuous" dataType="double"> 
       <FieldRef field="1GA_"/> 
      </DerivedField> 
     //100000 rows 
     </LocalTransformations> 
     <Segmentation multipleModelMethod="modelChain"> 
      <Segment id="1"> 
       <True/> 
       <RegressionModel functionName="regression"> 
        <MiningSchema> 
         <MiningField name="1GA_"/> 
        </MiningSchema> 
        <Output> 
         <OutputField name="decisionFunction_1" feature="predictedValue"/> 
         <OutputField name="logitDecisionFunction_1" optype="continuous" dataType="double" feature="transformedValue"> 
          <Apply function="logit"> 
<FieldRef field="decisionFunction_1"/> 
          </Apply> 
         </OutputField> 
        </Output> 
        <RegressionTable intercept="-5.303370169392045"> 
      <NumericPredictor name="x1" coefficient="0.18476274186559316"/> 
      //100000 rows of NumericPredictor 

     </RegressionTable> 
       </RegressionModel> 
       </Segment> 
       <Segment id="2"> 
        <True/> 
       <RegressionModel functionName="regression"> 
        <MiningSchema> 
         <MiningField name="logitDecisionFunction_1"/> 
        </MiningSchema> 
        <Output> 
         <OutputField name="logitDecisionFunction_0" 
    feature="predictedValue"/> 
        </Output> 
        <RegressionTable intercept="1.0"> 
      <NumericPredictor name="logitDecisionFunction_1" 

      coefficient="-1.0"/> 
         </RegressionTable> 
        </RegressionModel> 
       </Segment> 
       <Segment id="3"> 
        <True/> 
        <RegressionModel functionName="classification"> 
         <MiningSchema> 
          <MiningField name="GENDER" usageType="target"/> 
          <MiningField name="logitDecisionFunction_1"/> 
          <MiningField name="logitDecisionFunction_0"/> 
         </MiningSchema> 
         <RegressionTable intercept="0.0" targetCategory="1"> 
          <NumericPredictor name="logitDecisionFunction_1" 


    coefficient="1.0"/> 
        </RegressionTable> 
       <RegressionTable intercept="0.0" targetCategory="0"> 
         <NumericPredictor name="logitDecisionFunction_0" 


     coefficient="1.0"/> 
         </RegressionTable> 
        </RegressionModel> 
       </Segment> 
     </Segmentation> 
     </MiningModel> 
     </PMML> 

MLlibの代わりJpmmlを使用しようとの思いがあり は、ここで作業コード、今日です。 アイデア ありがとう

答えて

1

"負荷"とはどういう意味ですか? 「PMML文書をメモリ内のデータ構造に解析する」か「PMML文書を実行する」のどちらですか?

あなたのコードは、後者の目的であるようです。 JAXBUtil#unmarshalPMML(Source)メソッドが有効なPMMLドキュメントを含まないバイト配列で呼び出されるため(XMLパーサーは"....".getBytes("UTF-8")を受け付けません)、間違いなく失敗します。

また、「時間がかかる」とはどういう意味ですか? JAXBフレームワークの初期化コストは約1秒です。その後、毎秒200〜500MB(メガバイト)のPMMLコンテンツを非整列化できます。あなたはどれくらい必要ですか?

+0

こんにちは、コードが動作しています。長い時間がかかるのは、評価方法です。だから私はMLlibフォルダを使うと思った。 – userit1985

+0

だから、実際に "実行"を意味する "負荷"によって。 JPMMLは、PMMLドキュメントに格納されている実行計画に従ってモデルを実行しています。 PMMLドキュメントに無効な実行計画が含まれているため、実行が遅くなります。このPMMLドキュメントを生成するためにどのようなソフトウェアを使用しましたか? Apache Spark自身の「PMMLExportable」インターフェースは、非効率的な実行計画(例えば、単一のカテゴリのデータ列を何千もの連続したデータ列に拡張することができる)を生成することが知られていましたか? – user1808924

+0

私はpmmlスキーマを追加しました。助けてくれてありがとう – userit1985

関連する問題