Search in sources :

Example 1 with PMMLContextTest

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));
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) ArrayList(java.util.ArrayList) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) KiePMMLSegmentation(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Example 2 with PMMLContextTest

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);
}
Also used : PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest)

Example 3 with PMMLContextTest

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"));
}
Also used : PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest)

Example 4 with PMMLContextTest

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"));
}
Also used : PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest)

Example 5 with PMMLContextTest

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));
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLMiningModel(org.kie.pmml.models.mining.model.KiePMMLMiningModel) ArrayList(java.util.ArrayList) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) KiePMMLSegmentation(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)5 LinkedHashMap (java.util.LinkedHashMap)3 ArrayList (java.util.ArrayList)2 PMML4Result (org.kie.api.pmml.PMML4Result)2 KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)2 KiePMMLMiningModel (org.kie.pmml.models.mining.model.KiePMMLMiningModel)2 KiePMMLSegmentation (org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation)2 HashMap (java.util.HashMap)1