Search in sources :

Example 1 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class DecisionTreeTest method testWeightedConfidenceMissingValueStrategy.

@Test
public // @Ignore
void testWeightedConfidenceMissingValueStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_WEIGHTED_CONFIDENCE_MISSING_STRATEGY);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 30.0);
    PMML4Result resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtY");
    executor.setRunWithLogging(true);
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 50.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtX");
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) PMMLExecutor(org.kie.pmml.pmml_4_2.PMMLExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 2 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class DecisionTreeTest method testReturnLastNoTrueChildPredictionStrategy.

@Test
public void testReturnLastNoTrueChildPredictionStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_RETURN_LAST_NOTRUE_CHILD_STRATEGY);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 30.0);
    PMML4Result resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    String targetValue = resultHolder.getResultValue("Fld2", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isEqualTo("tgtY");
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 50.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    targetValue = resultHolder.getResultValue("Fld2", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isEqualTo("tgtX");
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) PMMLExecutor(org.kie.pmml.pmml_4_2.PMMLExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 3 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class DecisionTreeTest method testDefaultChildMissingValueStrategy.

@Test
public void testDefaultChildMissingValueStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_DEFAULT_CHILD_MISSING_STRATEGY);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 30.0);
    PMML4Result resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtY");
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 100.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    Assertions.assertThat(resultHolder.getResultValue("Fld3", "value", String.class).get()).isEqualTo("tgtZ");
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) KieBase(org.kie.api.KieBase) PMMLExecutor(org.kie.pmml.pmml_4_2.PMMLExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 4 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class DecisionTreeTest method testTreeFromMiningModel.

@Test
public void testTreeFromMiningModel() throws Exception {
    RuleUnitExecutor executor = createExecutor("org/kie/pmml/pmml_4_2/test_tree_from_mm.pmml");
    PMMLRequestData request = new PMMLRequestData("1234", "SampleMineTree1");
    request.addRequestParam("fld1", 30.0);
    request.addRequestParam("fld2", 60.0);
    request.addRequestParam("fld3", "false");
    request.addRequestParam("fld4", "optA");
    PMML4Result resultHolder = new PMML4Result();
    List<String> possiblePackages = calculatePossiblePackageNames("SampleMineTree1");
    Class<? extends RuleUnit> unitClass = getStartingRuleUnit("RuleUnitIndicator", (InternalKnowledgeBase) kbase, possiblePackages);
    assertNotNull(unitClass);
    int x = executor.run(unitClass);
    assertTrue(x > 0);
    data.insert(request);
    resultData.insert(resultHolder);
    executor.run(unitClass);
    assertEquals("OK", resultHolder.getResultCode());
    assertNotNull(resultHolder.getResultVariables());
    assertNotNull(resultHolder.getResultValue("Fld5", null));
    String value = resultHolder.getResultValue("Fld5", "value", String.class).orElse(null);
    assertEquals("tgtY", value);
    System.out.println(resultHolder);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) RuleUnitExecutor(org.kie.api.runtime.rule.RuleUnitExecutor) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 5 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class DecisionTreeTest method testMissingTreeWeighted2.

@Test
public void testMissingTreeWeighted2() throws Exception {
    Resource res = ResourceFactory.newClassPathResource(source2);
    KieBase kbase = new KieHelper().addResource(res, ResourceType.PMML).build();
    RuleUnitExecutor executor = RuleUnitExecutor.create().bind(kbase);
    KieRuntimeLogger console = ((InternalRuleUnitExecutor) executor).addConsoleLogger();
    PMMLRequestData requestData = new PMMLRequestData("123", "Missing");
    requestData.addRequestParam(new ParameterInfo<>("123", "fld1", Double.class, -1.0));
    requestData.addRequestParam(new ParameterInfo<>("123", "fld2", Double.class, -1.0));
    requestData.addRequestParam(new ParameterInfo<>("123", "fld3", String.class, "miss"));
    PMML4Result resultHolder = new PMML4Result();
    DataSource<PMMLRequestData> data = executor.newDataSource("request");
    DataSource<PMML4Result> results = executor.newDataSource("results");
    DataSource<PMML4Data> pmmlData = executor.newDataSource("pmmlData");
    List<String> possiblePackages = calculatePossiblePackageNames("Missing");
    Class<? extends RuleUnit> unitClass = getStartingRuleUnit("RuleUnitIndicator", (InternalKnowledgeBase) kbase, possiblePackages);
    assertNotNull(unitClass);
    int x = executor.run(unitClass);
    data.insert(requestData);
    results.insert(resultHolder);
    executor.run(unitClass);
    console.close();
    System.out.println(resultHolder);
    Collection<?> objects = ((InternalRuleUnitExecutor) executor).getSessionObjects();
    objects.forEach(o -> {
        System.out.println(o);
    });
    pmmlData.forEach(pd -> {
        System.out.println(pd);
    });
    AbstractTreeToken token = (AbstractTreeToken) resultHolder.getResultValue("MissingTreeToken", null);
    assertNotNull(token);
    assertEquals(0.6, token.getConfidence(), 1e-6);
    assertEquals("null", token.getCurrent());
    assertEquals(100.0, token.getTotalCount(), 0.0);
    Object fld9 = resultHolder.getResultValue("Fld9", null);
    assertNotNull(fld9);
    String value = (String) resultHolder.getResultValue("Fld9", "value");
    assertNotNull(value);
    assertEquals("tgtX", value);
}
Also used : InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) PMMLRequestData(org.kie.api.pmml.PMMLRequestData) PMML4Result(org.kie.api.pmml.PMML4Result) Resource(org.kie.api.io.Resource) PMML4Data(org.kie.api.pmml.PMML4Data) KieHelper(org.kie.internal.utils.KieHelper) KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) InternalRuleUnitExecutor(org.drools.core.impl.InternalRuleUnitExecutor) RuleUnitExecutor(org.kie.api.runtime.rule.RuleUnitExecutor) KieBase(org.kie.api.KieBase) AbstractTreeToken(org.kie.pmml.pmml_4_2.model.tree.AbstractTreeToken) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Aggregations

PMMLRequestData (org.kie.api.pmml.PMMLRequestData)68 Test (org.junit.Test)53 PMML4Result (org.kie.api.pmml.PMML4Result)30 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)28 InternalRuleUnitExecutor (org.drools.core.impl.InternalRuleUnitExecutor)17 RuleUnitExecutor (org.kie.api.runtime.rule.RuleUnitExecutor)17 KieBase (org.kie.api.KieBase)16 KiePMMLMiningField (org.kie.pmml.commons.model.KiePMMLMiningField)16 ParameterInfo (org.kie.api.pmml.ParameterInfo)14 KiePMMLInterval (org.kie.pmml.commons.model.expressions.KiePMMLInterval)14 Map (java.util.Map)13 PMMLExecutor (org.kie.pmml.pmml_4_2.PMMLExecutor)11 ArrayList (java.util.ArrayList)9 Arrays (java.util.Arrays)9 Collections (java.util.Collections)9 List (java.util.List)9 Optional (java.util.Optional)9 IntStream (java.util.stream.IntStream)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)9