Search in sources :

Example 6 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue 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 7 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class PMMLMiningModelEvaluatorTest method getKiePMMLNameValueValueWeightNumber.

@Test
public void getKiePMMLNameValueValueWeightNumber() {
    final Integer rawObject = 24;
    final PMML4Result pmml4Result = getPMML4Result(rawObject);
    final double weight = 2.23;
    double expected = rawObject.doubleValue();
    VALUE_WEIGHT_METHODS.forEach(multipleModelMethod -> {
        KiePMMLNameValue retrieved = evaluator.getKiePMMLNameValue(pmml4Result, multipleModelMethod, weight);
        assertNotNull(retrieved);
        assertEquals(pmml4Result.getResultObjectName(), retrieved.getName());
        assertNotNull(retrieved.getValue());
        assertTrue(retrieved.getValue() instanceof KiePMMLValueWeight);
        KiePMMLValueWeight kiePMMLValueWeight = (KiePMMLValueWeight) retrieved.getValue();
        assertEquals(expected, kiePMMLValueWeight.getValue(), 0.0);
        assertEquals(weight, kiePMMLValueWeight.getWeight(), 0.0);
    });
}
Also used : PMML4Result(org.kie.api.pmml.PMML4Result) KiePMMLValueWeight(org.kie.pmml.commons.model.tuples.KiePMMLValueWeight) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) PMMLContextTest(org.kie.pmml.commons.testingutility.PMMLContextTest) Test(org.junit.Test)

Example 8 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class MULTIPLE_MODEL_METHODTest method applyAVERAGENotKiePMMLValueWeight.

@Test(expected = KieEnumException.class)
public void applyAVERAGENotKiePMMLValueWeight() {
    LinkedHashMap<String, KiePMMLNameValue> inputData = new LinkedHashMap<>();
    Object EXPECTED = "EXPECTED";
    inputData.put("ValueA", new KiePMMLNameValue("valuea", "dvsdv"));
    inputData.put("ValueB", new KiePMMLNameValue("valueb", EXPECTED));
    inputData.put("ValueC", new KiePMMLNameValue("valuec", "dssd"));
    inputData.put("ValueD", new KiePMMLNameValue("valuex", EXPECTED));
    inputData.put("ValueE", new KiePMMLNameValue("valueb", "vsd"));
    AVERAGE.applyPrediction(inputData);
}
Also used : KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 9 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class MULTIPLE_MODEL_METHODTest method applyWEIGHTED_SUMNotNumbers.

@Test(expected = KieEnumException.class)
public void applyWEIGHTED_SUMNotNumbers() {
    LinkedHashMap<String, KiePMMLNameValue> inputData = new LinkedHashMap<>();
    Object EXPECTED = "EXPECTED";
    inputData.put("ValueA", new KiePMMLNameValue("valuea", "dvsdv"));
    inputData.put("ValueB", new KiePMMLNameValue("valueb", EXPECTED));
    inputData.put("ValueC", new KiePMMLNameValue("valuec", "dssd"));
    inputData.put("ValueD", new KiePMMLNameValue("valuex", EXPECTED));
    inputData.put("ValueE", new KiePMMLNameValue("valueb", "vsd"));
    WEIGHTED_SUM.applyPrediction(inputData);
}
Also used : KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 10 with KiePMMLNameValue

use of org.kie.pmml.commons.model.tuples.KiePMMLNameValue in project drools by kiegroup.

the class MULTIPLE_MODEL_METHODTest method applyWEIGHTED_AVERAGENotKiePMMLValueWeight.

@Test(expected = KieEnumException.class)
public void applyWEIGHTED_AVERAGENotKiePMMLValueWeight() {
    LinkedHashMap<String, KiePMMLNameValue> inputData = new LinkedHashMap<>();
    Object EXPECTED = "EXPECTED";
    inputData.put("ValueA", new KiePMMLNameValue("valuea", "dvsdv"));
    inputData.put("ValueB", new KiePMMLNameValue("valueb", EXPECTED));
    inputData.put("ValueC", new KiePMMLNameValue("valuec", "dssd"));
    inputData.put("ValueD", new KiePMMLNameValue("valuex", EXPECTED));
    inputData.put("ValueE", new KiePMMLNameValue("valueb", "vsd"));
    WEIGHTED_AVERAGE.applyPrediction(inputData);
}
Also used : KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

KiePMMLNameValue (org.kie.pmml.commons.model.tuples.KiePMMLNameValue)44 Test (org.junit.Test)37 CommonTestingUtility.getProcessingDTO (org.kie.pmml.commons.CommonTestingUtility.getProcessingDTO)19 ProcessingDTO (org.kie.pmml.commons.model.ProcessingDTO)19 LinkedHashMap (java.util.LinkedHashMap)16 ArrayList (java.util.ArrayList)8 List (java.util.List)8 HashMap (java.util.HashMap)7 PMML4Result (org.kie.api.pmml.PMML4Result)7 Map (java.util.Map)6 Collectors (java.util.stream.Collectors)6 IntStream (java.util.stream.IntStream)6 Assert.assertEquals (org.junit.Assert.assertEquals)6 KiePMMLFieldRef (org.kie.pmml.commons.model.expressions.KiePMMLFieldRef)6 KiePMMLDerivedField (org.kie.pmml.commons.transformations.KiePMMLDerivedField)6 Collections (java.util.Collections)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 Arrays (java.util.Arrays)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 PMMLContextTest (org.kie.pmml.commons.testingutility.PMMLContextTest)4