use of org.kie.pmml.api.exceptions.KieEnumException in project drools by kiegroup.
the class PMMLMiningModelEvaluator method getPMML4Result.
PMML4Result getPMML4Result(final KiePMMLMiningModel toEvaluate, final LinkedHashMap<String, KiePMMLNameValueProbabilityMapTuple> inputData, final PMMLContext pmmlContext) {
final MULTIPLE_MODEL_METHOD multipleModelMethod = toEvaluate.getSegmentation().getMultipleModelMethod();
Object result = null;
LinkedHashMap<String, Double> probabilityResultMap = null;
ResultCode resultCode = OK;
final LinkedHashMap<String, KiePMMLNameValue> toUseForPrediction = new LinkedHashMap<>();
final LinkedHashMap<String, List<KiePMMLNameValue>> toUseForProbability = new LinkedHashMap<>();
inputData.forEach((key, value) -> {
toUseForPrediction.put(key, value.predictionValue);
toUseForProbability.put(key, value.probabilityValues);
});
try {
if (MINING_FUNCTION.CLASSIFICATION.equals(toEvaluate.getMiningFunction())) {
result = multipleModelMethod.applyClassification(toUseForPrediction);
probabilityResultMap = multipleModelMethod.applyProbability(toUseForProbability);
} else {
result = multipleModelMethod.applyPrediction(toUseForPrediction);
}
} catch (KieEnumException e) {
logger.warn(e.getMessage());
resultCode = FAIL;
}
pmmlContext.setProbabilityResultMap(probabilityResultMap);
PMML4Result toReturn = new PMML4Result();
toReturn.addResultVariable(toEvaluate.getTargetField(), result);
toReturn.setResultObjectName(toEvaluate.getTargetField());
toReturn.setResultCode(resultCode.getName());
return toReturn;
}
Aggregations