use of org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD 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;
}
use of org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD in project drools by kiegroup.
the class PMMLMiningModelEvaluator method evaluateMiningModel.
/**
* Evaluate the whole <code>KiePMMLMiningModel</code>
* Being it a <b>meta</b> model, it actually works as the top-level PMML model,
* recursively and indirectly invoking model-specific evaluators (through <code>PMMLRuntime</code> container)
* @param toEvaluate
* @param pmmlContext
* @param knowledgeBase
* @return
*/
private PMML4Result evaluateMiningModel(final KiePMMLMiningModel toEvaluate, final PMMLContext pmmlContext, final KieBase knowledgeBase) {
final MULTIPLE_MODEL_METHOD multipleModelMethod = toEvaluate.getSegmentation().getMultipleModelMethod();
final List<KiePMMLSegment> segments = toEvaluate.getSegmentation().getSegments();
final LinkedHashMap<String, KiePMMLNameValueProbabilityMapTuple> inputData = new LinkedHashMap<>();
for (KiePMMLSegment segment : segments) {
Optional<PMML4Result> segmentResult = evaluateSegment(segment, pmmlContext, knowledgeBase, toEvaluate.getName());
segmentResult.ifPresent(pmml4Result -> populateInputDataWithSegmentResult(pmml4Result, pmmlContext, multipleModelMethod, segment, inputData));
}
return getPMML4Result(toEvaluate, inputData, pmmlContext);
}
Aggregations