JPMML如果缺少输入值,谓词将评估为未知(即空引用)

时间:2017-02-13 20:31:51

标签: java null pmml

我正在使用jpmml.evaluator.version 1.3.4& jpmml.model.version 1.3.5。

我为评估准备参数并得到错误: org.jpmml.evaluator.MissingValueException(在10678行或附近):decisionFunction_1     在org.jpmml.evaluator.mining.MiningModelEvaluator.evaluateSegmentation(MiningModelEvaluator.java:436)     at org.jpmml.evaluator.mining.MiningModelEvaluator.evaluateClassification(MiningModelEvaluator.java:240)     在org.jpmml.evaluator.mining.MiningModelEvaluator.evaluate(MiningModelEvaluator.java:207)     在org.jpmml.evaluator.mining.MiningModelEvaluator.evaluate(MiningModelEvaluator.java:185)

代码:

//Feature class has 2 fields: String name, Object value

 public Double evaluate(List<Feature> givenFeaturesValue)  {
  Map<FieldName, FieldValue> arguments = new HashMap<>();

List<InputField> inputFields = evaluator.getInputFields();
Map<FieldName, InputField> featureProperties= new HashMap<>(inputFields.size());
        for(InputField inputField : inputFields) {
                    featureProperties.put(inputField.getName(), inputField);
        }

for(Entry<FieldName, InputField> featureProperty: featureProperties.entrySet()) {
            FieldValue value = featureProperty.getValue().prepare(null);    
            arguments.put(featureProperty.getKey(), value);
    }

    for(Entry<FieldName, InputField> featureProperty: featureProperties.entrySet()) {
        for(Feature givenFeature: givenFeaturesValue) {
            if(givenFeature.getFieldName().equals(featureProperty.getKey().getValue())) {
                FieldValue value = givenFeature.getValue().prepare(featureProperty.getValue());             
                arguments.put(featureProperty.getKey(), value);
            }
        }
    }

Map<FieldName, ?> results = evaluator.evaluate(arguments);

   //after this line I get the error
}

PMML文件:

<DataDictionary>
    <DataField name="GENDER" optype="categorical" dataType="string">
        <Value value="0"/>
        <Value value="1"/>
    </DataField>
    <DataField name="1GA" optype="categorical" dataType="string">
        <Value value="1GA DEFAULT"/>
        <Value value=""/>
        <Value value="&quot;"/>
        <Value value="#"/>
        <Value value="#NUM#"/>
</DataField>
    <DataField name="DB10" optype="categorical" dataType="integer">
        <Value value="0"/>
        <Value value="1"/>
    </DataField>
 <DataField name="ILR" optype="continuous" dataType="double"/>
 </DataDictionary>

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

只为此输入字段提供非null值(而不是null值)。

此例外是JPMML-Evaluator等效于java.lang.NullPointerException。您是否知道如何使用Java(以及其他基于JVM的语言)处理NPE?