尝试在java中加载时,jpmml中的InvalidFeatureException

时间:2016-09-26 09:31:10

标签: pmml

我的pmml文件链接。由R-Tool生成

pmml file on google drive

这是我的java代码..

PMML model = null;
    File inputFilePath = new File("/home/equation/iris_rf.pmml");
    try (InputStream is = new FileInputStream(inputFilePath)) {
        model = org.jpmml.model.PMMLUtil.unmarshal(is);
    } catch (Exception e) {
        throw e;
    }

    // construct a tree predictor based on the PMML
    ModelEvaluator<TreeModel> modelEvaluator = new TreeModelEvaluator(model);
    System.out.println(modelEvaluator.getSummary());

例外---

Exception in thread "main" org.jpmml.evaluator.InvalidFeatureException: PMML
at org.jpmml.evaluator.ModelEvaluator.selectModel(ModelEvaluator.java:528)
at org.jpmml.evaluator.tree.TreeModelEvaluator.<init>(TreeModelEvaluator.java:64)
at com.girnarsoft.Pmml.main(Pmml.java:24)

任何想法?为什么会出现这个错误?

1 个答案:

答案 0 :(得分:1)

您必须实例化与PMML文件的顶级Model元素匹配的org.jpmml.evaluator.ModelEvaluator子类。

目前,您正在实例化org.jpmml.evaluator.tree.TreeModelEvaluator,其对应于TreeModel element。但是,您应该实例化org.jpmml.evaluator.mining.MiningModelEvaluator,因为PMML文件中的顶级Model元素是MiningModel element

通常,您应该使用ModelEvaluator工厂方法构建ModelEvaluatorFactory#newModelEvaluator(PMML)个实例。