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);
}
Aggregations