Search in sources :

Example 1 with MULTIPLE_MODEL_METHOD

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

Example 2 with MULTIPLE_MODEL_METHOD

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);
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLSegment(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment) MULTIPLE_MODEL_METHOD(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2 PMML4Result (org.kie.api.pmml.PMML4Result)2 MULTIPLE_MODEL_METHOD (org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD)2 List (java.util.List)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 KiePMMLSegment (org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment)1