Search in sources :

Example 1 with MiningModelEvaluator

use of org.jpmml.evaluator.mining.MiningModelEvaluator in project shifu by ShifuML.

the class PMMLScoreGenTest method genPMMLAndCompareScore.

private void genPMMLAndCompareScore(String modelName, String evalDataSet, String evalSetName, String delimiter) throws Exception {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(ExportModelProcessor.IS_CONCISE, true);
    ShifuCLI.exportModel(ExportModelProcessor.ONE_BAGGING_PMML_MODEL, params);
    int totalRecordCnt = 0;
    int matchRecordCnt = 0;
    CsvFile evalScoreFile = new CsvFile("evals" + File.separator + evalSetName + File.separator + "EvalScore", "|", true);
    Iterator<Map<String, String>> scoreIterator = evalScoreFile.iterator();
    // skip first line
    scoreIterator.next();
    CsvFile evalData = new CsvFile(evalDataSet, delimiter, true);
    PMML pmml = PMMLUtils.loadPMML("pmmls" + File.separator + modelName + ".pmml");
    MiningModelEvaluator evaluator = new MiningModelEvaluator(pmml);
    Iterator<Map<String, String>> iterator = evalData.iterator();
    while (iterator.hasNext() && scoreIterator.hasNext()) {
        Map<String, String> rawInput = iterator.next();
        double pmmlScore = score(evaluator, rawInput, "FinalResult");
        Map<String, String> scoreInput = scoreIterator.next();
        double evalScore = Double.parseDouble(scoreInput.get("mean"));
        totalRecordCnt++;
        if (Math.abs(evalScore - pmmlScore) < EPS) {
            matchRecordCnt++;
        }
    }
    Assert.assertTrue(matchRecordCnt == totalRecordCnt);
}
Also used : HashMap(java.util.HashMap) MiningModelEvaluator(org.jpmml.evaluator.mining.MiningModelEvaluator) PMML(org.dmg.pmml.PMML) CsvFile(ml.shifu.shifu.combo.CsvFile) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 CsvFile (ml.shifu.shifu.combo.CsvFile)1 PMML (org.dmg.pmml.PMML)1 MiningModelEvaluator (org.jpmml.evaluator.mining.MiningModelEvaluator)1