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