use of org.kie.pmml.commons.testingutility.PMMLContextTest in project drools by kiegroup.
the class PMMLMiningModelEvaluatorTest method getPMML4ResultFAIL.
@Test
public void getPMML4ResultFAIL() {
String name = "NAME";
String targetField = "TARGET";
KiePMMLSegmentation kiePMMLSegmentation = KiePMMLSegmentation.builder("SEGM_1", Collections.emptyList(), AVERAGE).build();
KiePMMLMiningModel kiePMMLMiningModel = KiePMMLMiningModel.builder(name, Collections.emptyList(), MINING_FUNCTION.ASSOCIATION_RULES).withTargetField(targetField).withSegmentation(kiePMMLSegmentation).build();
final LinkedHashMap<String, PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple> inputData = new LinkedHashMap<>();
inputData.put("FIRST_KEY", new PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple(new KiePMMLNameValue("FIRST_NAME", "FIRST_VALUE"), new ArrayList<>()));
inputData.put("SECOND_KEY", new PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple(new KiePMMLNameValue("SECOND_NAME", "SECOND_VALUE"), new ArrayList<>()));
PMML4Result retrieved = evaluator.getPMML4Result(kiePMMLMiningModel, inputData, new PMMLContextTest());
assertNotNull(retrieved);
assertEquals(FAIL.getName(), retrieved.getResultCode());
assertEquals(targetField, retrieved.getResultObjectName());
final Map<String, Object> resultVariables = retrieved.getResultVariables();
assertTrue(resultVariables.containsKey(targetField));
assertNull(resultVariables.get(targetField));
}
use of org.kie.pmml.commons.testingutility.PMMLContextTest in project drools by kiegroup.
the class KiePMMLClassificationTableTest method evaluateRegression.
@Test
public void evaluateRegression() {
PMMLContextTest pmmlContextTest = new PMMLContextTest();
Map<String, Object> input = new HashMap<>();
input.put(CASE_A, firstTableResult);
input.put(CASE_B, secondTableResult);
Object retrieved = classificationTable.evaluateRegression(input, pmmlContextTest);
assertEquals(expectedResult, retrieved);
final Map<String, Double> probabilityResultMap = pmmlContextTest.getProbabilityResultMap();
assertEquals(firstExpectedValue, probabilityResultMap.get(CASE_A), 0);
assertEquals(secondExpectedValue, probabilityResultMap.get(CASE_B), 0);
}
use of org.kie.pmml.commons.testingutility.PMMLContextTest in project drools by kiegroup.
the class KiePMMLCharacteristicsTest method evaluate.
@Test
public void evaluate() {
Double initialScore = 25.23;
KiePMMLCharacteristics kiePMMLCharacteristics = new KiePMMLCharacteristics("NAME", Collections.emptyList(), getKiePMMLCharacteristicList());
PMMLContextTest pmmlContextTest = new PMMLContextTest();
Optional<Number> retrieved = kiePMMLCharacteristics.evaluate(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyMap(), pmmlContextTest, initialScore, REASONCODE_ALGORITHM.POINTS_BELOW, true, 0);
assertNotNull(retrieved);
assertTrue(retrieved.isPresent());
Double EVALUATION_20 = baselineScore - value2;
Double EVALUATION_11 = baselineScore - value1;
Double expected = initialScore + value2 + value1 + 1;
assertEquals(expected, retrieved.get());
final Map<String, Object> outputFieldsMap = pmmlContextTest.getOutputFieldsMap();
assertEquals(2, outputFieldsMap.size());
assertTrue(outputFieldsMap.containsKey("REASON_CODE_20"));
assertEquals(EVALUATION_20, outputFieldsMap.get("REASON_CODE_20"));
assertTrue(outputFieldsMap.containsKey("REASON_CODE_11"));
assertEquals(EVALUATION_11, outputFieldsMap.get("REASON_CODE_11"));
}
use of org.kie.pmml.commons.testingutility.PMMLContextTest in project drools by kiegroup.
the class KiePMMLScorecardModelTest method evaluate.
@Test
public void evaluate() {
Double initialScore = 25.23;
PMMLContextTest pmmlContextTest = new PMMLContextTest();
KiePMMLScorecardModel kiePMMLScorecardModel = new KiePMMLScorecardModel(MODEL_NAME, Collections.emptyList(), getKiePMMLCharacteristics(), initialScore, true, REASONCODE_ALGORITHM.POINTS_BELOW, 0);
Object retrieved = kiePMMLScorecardModel.evaluate(null, Collections.emptyMap(), pmmlContextTest);
assertNotNull(retrieved);
Double EVALUATION_20 = baselineScore - value2;
Double EVALUATION_11 = baselineScore - value1;
Double expected = initialScore + value2 + value1 + 1;
assertEquals(expected, retrieved);
final Map<String, Object> outputFieldsMap = pmmlContextTest.getOutputFieldsMap();
assertEquals(2, outputFieldsMap.size());
assertTrue(outputFieldsMap.containsKey("REASON_CODE_20"));
assertEquals(EVALUATION_20, outputFieldsMap.get("REASON_CODE_20"));
assertTrue(outputFieldsMap.containsKey("REASON_CODE_11"));
assertEquals(EVALUATION_11, outputFieldsMap.get("REASON_CODE_11"));
}
use of org.kie.pmml.commons.testingutility.PMMLContextTest in project drools by kiegroup.
the class PMMLMiningModelEvaluatorTest method getPMML4ResultOK.
@Test
public void getPMML4ResultOK() {
String name = "NAME";
String targetField = "TARGET";
String prediction = "FIRST_VALUE";
KiePMMLSegmentation kiePMMLSegmentation = KiePMMLSegmentation.builder("SEGM_1", Collections.emptyList(), SELECT_FIRST).build();
KiePMMLMiningModel kiePMMLMiningModel = KiePMMLMiningModel.builder(name, Collections.emptyList(), MINING_FUNCTION.ASSOCIATION_RULES).withTargetField(targetField).withSegmentation(kiePMMLSegmentation).build();
final LinkedHashMap<String, PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple> inputData = new LinkedHashMap<>();
inputData.put("FIRST_KEY", new PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple(new KiePMMLNameValue("FIRST_NAME", prediction), new ArrayList<>()));
inputData.put("SECOND_KEY", new PMMLMiningModelEvaluator.KiePMMLNameValueProbabilityMapTuple(new KiePMMLNameValue("SECOND_NAME", "SECOND_VALUE"), new ArrayList<>()));
PMML4Result retrieved = evaluator.getPMML4Result(kiePMMLMiningModel, inputData, new PMMLContextTest());
assertNotNull(retrieved);
assertEquals(OK.getName(), retrieved.getResultCode());
assertEquals(targetField, retrieved.getResultObjectName());
final Map<String, Object> resultVariables = retrieved.getResultVariables();
assertTrue(resultVariables.containsKey(targetField));
assertEquals(prediction, resultVariables.get(targetField));
}
Aggregations