Search in sources :

Example 1 with KiePMMLSegmentation

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

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

the class KiePMMLMiningModelTest method getSegmentation.

@Test
public void getSegmentation() {
    assertNull(KIE_PMML_MINING_MODEL.getSegmentation());
    final KiePMMLSegmentation segmentation = getKiePMMLSegmentation("SEGMENTATION_NAME");
    KIE_PMML_MINING_MODEL = BUILDER.withSegmentation(segmentation).build();
    assertEquals(segmentation, KIE_PMML_MINING_MODEL.getSegmentation());
}
Also used : AbstractKiePMMLMiningModelTest.getKiePMMLSegmentation(org.kie.pmml.models.mining.model.AbstractKiePMMLMiningModelTest.getKiePMMLSegmentation) KiePMMLSegmentation(org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation) Test(org.junit.Test) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest)

Example 3 with KiePMMLSegmentation

use of org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation 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)3 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)3 KiePMMLSegmentation (org.kie.pmml.models.mining.model.segmentation.KiePMMLSegmentation)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)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 AbstractKiePMMLMiningModelTest.getKiePMMLSegmentation (org.kie.pmml.models.mining.model.AbstractKiePMMLMiningModelTest.getKiePMMLSegmentation)1