Search in sources :

Example 11 with KiePMMLNameValue

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

the class MULTIPLE_MODEL_METHODTest method applyWEIGHTED_MAJORITY_VOTE.

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

Example 12 with KiePMMLNameValue

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

the class MULTIPLE_MODEL_METHODTest method applyMAJORITY_VOTE.

@Test
public void applyMAJORITY_VOTE() {
    LinkedHashMap<String, KiePMMLNameValue> inputData = new LinkedHashMap<>();
    Object EXPECTED = 3;
    inputData.put("ValueA", new KiePMMLNameValue("valuea", 1));
    inputData.put("ValueB", new KiePMMLNameValue("valueb", EXPECTED));
    inputData.put("ValueC", new KiePMMLNameValue("valuec", EXPECTED));
    inputData.put("ValueD", new KiePMMLNameValue("valuex", EXPECTED));
    inputData.put("ValueE", new KiePMMLNameValue("valueb", 1));
    Object retrieved = MAJORITY_VOTE.applyPrediction(inputData);
    assertEquals(EXPECTED, retrieved);
    inputData = new LinkedHashMap<>();
    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"));
    retrieved = MAJORITY_VOTE.applyPrediction(inputData);
    assertEquals(EXPECTED, retrieved);
}
Also used : KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 13 with KiePMMLNameValue

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

the class MULTIPLE_MODEL_METHODTest method applyMAXNotNumbers.

@Test(expected = KieEnumException.class)
public void applyMAXNotNumbers() {
    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"));
    MAX.applyPrediction(inputData);
}
Also used : KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 14 with KiePMMLNameValue

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

the class MULTIPLE_MODEL_METHODTest method applySELECT_FIRSTNotNumbers.

@Test
public void applySELECT_FIRSTNotNumbers() {
    LinkedHashMap<String, KiePMMLNameValue> inputData = new LinkedHashMap<>();
    Object EXPECTED = "EXPECTED";
    inputData.put("ValueA", new KiePMMLNameValue("valuea", EXPECTED));
    inputData.put("ValueB", new KiePMMLNameValue("valueb", "vdsvsd"));
    inputData.put("ValueC", new KiePMMLNameValue("valuec", "dssd"));
    inputData.put("ValueD", new KiePMMLNameValue("valuex", "vfdsvsdeeee"));
    inputData.put("ValueE", new KiePMMLNameValue("valueb", "vsd"));
    Object retrieved = SELECT_FIRST.applyPrediction(inputData);
    assertEquals(EXPECTED, retrieved);
}
Also used : KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 15 with KiePMMLNameValue

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

the class MULTIPLE_MODEL_METHODTest method applySELECT_ALLNumbers.

@Test
public void applySELECT_ALLNumbers() {
    Map<String, Object> expectedKiePMMLValueWeightMap = getExpectedKiePMMLValueWeightMap(true);
    LinkedHashMap<String, KiePMMLNameValue> inputData = (LinkedHashMap<String, KiePMMLNameValue>) expectedKiePMMLValueWeightMap.get("inputData");
    List<Double> expected = inputData.values().stream().map(kiePMMLNameValue -> ((KiePMMLValueWeight) kiePMMLNameValue.getValue()).getValue()).collect(Collectors.toList());
    List retrieved = (List) SELECT_ALL.applyPrediction(inputData);
    assertEquals(expected.size(), retrieved.size());
    for (Double expDouble : expected) {
        assertTrue(retrieved.contains(expDouble));
    }
    expectedKiePMMLValueWeightMap = getExpectedKiePMMLValueWeightMap(false);
    inputData = (LinkedHashMap<String, KiePMMLNameValue>) expectedKiePMMLValueWeightMap.get("inputData");
    expected = inputData.values().stream().map(kiePMMLNameValue -> ((KiePMMLValueWeight) kiePMMLNameValue.getValue()).getValue()).collect(Collectors.toList());
    retrieved = (List) SELECT_ALL.applyPrediction(inputData);
    assertEquals(expected.size(), retrieved.size());
    for (Double expDouble : expected) {
        assertTrue(retrieved.contains(expDouble));
    }
}
Also used : IntStream(java.util.stream.IntStream) MAX(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MAX) Arrays(java.util.Arrays) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) WEIGHTED_AVERAGE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_AVERAGE) ArrayList(java.util.ArrayList) SELECT_ALL(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SELECT_ALL) LinkedHashMap(java.util.LinkedHashMap) MEDIAN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MEDIAN) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) WEIGHTED_MAJORITY_VOTE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_MAJORITY_VOTE) Map(java.util.Map) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) WEIGHTED_SUM(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_SUM) KiePMMLValueWeight(org.kie.pmml.commons.model.tuples.KiePMMLValueWeight) Assert.assertNotNull(org.junit.Assert.assertNotNull) MAJORITY_VOTE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MAJORITY_VOTE) SUM(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SUM) KieEnumException(org.kie.pmml.api.exceptions.KieEnumException) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) SELECT_FIRST(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.SELECT_FIRST) AVERAGE(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.AVERAGE) AbstractMap(java.util.AbstractMap) List(java.util.List) MODEL_CHAIN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.MODEL_CHAIN) Stream(java.util.stream.Stream) Assert.assertEquals(org.junit.Assert.assertEquals) WEIGHTED_MEDIAN(org.kie.pmml.models.mining.model.enums.MULTIPLE_MODEL_METHOD.WEIGHTED_MEDIAN) KiePMMLValueWeight(org.kie.pmml.commons.model.tuples.KiePMMLValueWeight) KiePMMLNameValue(org.kie.pmml.commons.model.tuples.KiePMMLNameValue) ArrayList(java.util.ArrayList) List(java.util.List) 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