Search in sources :

Example 1 with KiePMMLSegment

use of org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment in project drools by kiegroup.

the class PMMLMiningModelEvaluatorTest method getStep.

@Test
public void getStep() {
    final String modelName = "MODEL_NAME";
    KiePMMLModel modelMock = mock(KiePMMLModel.class);
    when(modelMock.getName()).thenReturn(modelName);
    final String segmentName = "SEGMENT_NAME";
    KiePMMLSegment segmentMock = mock(KiePMMLSegment.class);
    when(segmentMock.getName()).thenReturn(segmentName);
    when(segmentMock.getModel()).thenReturn(modelMock);
    final String resultObjectName = "RESULT_OBJECT_NAME";
    final String resultObjectValue = "RESULT_OBJECT_VALUE";
    ResultCode resultCode = OK;
    PMML4Result pmml4Result = new PMML4Result();
    pmml4Result.setResultCode(resultCode.getName());
    pmml4Result.setResultObjectName(resultObjectName);
    pmml4Result.getResultVariables().put(resultObjectName, resultObjectValue);
    PMMLStep retrieved = evaluator.getStep(segmentMock, pmml4Result);
    assertNotNull(retrieved);
    assertTrue(retrieved instanceof PMMLMiningModelStep);
    Map<String, Object> retrievedInfo = retrieved.getInfo();
    assertNotNull(retrievedInfo);
    assertEquals(segmentName, retrievedInfo.get("SEGMENT"));
    assertEquals(modelName, retrievedInfo.get("MODEL"));
    assertEquals(resultCode.getName(), retrievedInfo.get("RESULT CODE"));
    assertEquals(resultObjectValue, retrievedInfo.get("RESULT"));
    resultCode = FAIL;
    pmml4Result = new PMML4Result();
    pmml4Result.setResultCode(resultCode.getName());
    retrieved = evaluator.getStep(segmentMock, pmml4Result);
    assertNotNull(retrieved);
    assertTrue(retrieved instanceof PMMLMiningModelStep);
    retrievedInfo = retrieved.getInfo();
    assertNotNull(retrievedInfo);
    assertEquals(segmentName, retrievedInfo.get("SEGMENT"));
    assertEquals(modelName, retrievedInfo.get("MODEL"));
    assertEquals(resultCode.getName(), retrievedInfo.get("RESULT CODE"));
    assertFalse(retrievedInfo.containsKey("RESULT"));
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) PMMLStep(org.kie.pmml.api.models.PMMLStep) KiePMMLModel(org.kie.pmml.commons.model.KiePMMLModel) KiePMMLSegment(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment) ResultCode(org.kie.pmml.api.enums.ResultCode) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Example 2 with KiePMMLSegment

use of org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment 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

PMML4Result (org.kie.api.pmml.PMML4Result)2 KiePMMLSegment (org.kie.pmml.models.mining.model.segmentation.KiePMMLSegment)2 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.Test)1 ResultCode (org.kie.pmml.api.enums.ResultCode)1 PMMLStep (org.kie.pmml.api.models.PMMLStep)1 KiePMMLModel (org.kie.pmml.commons.model.KiePMMLModel)1 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)1 MULTIPLE_MODEL_METHOD (org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD)1