Search in sources :

Example 1 with KieEnumException

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;
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) KieEnumException(org.kie.pmml.api.exceptions.KieEnumException) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ResultCode(org.kie.pmml.api.enums.ResultCode) MULTIPLE_MODEL_METHOD(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 PMML4Result (org.kie.api.pmml.PMML4Result)1 ResultCode (org.kie.pmml.api.enums.ResultCode)1 KieEnumException (org.kie.pmml.api.exceptions.KieEnumException)1 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)1 MULTIPLE_MODEL_METHOD (org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD)1