Search in sources :

Example 1 with PMMLExecutor

use of org.kie.pmml.pmml_4_2.PMMLExecutor 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 PMMLExecutor

use of org.kie.pmml.pmml_4_2.PMMLExecutor 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 PMMLExecutor

use of org.kie.pmml.pmml_4_2.PMMLExecutor 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 PMMLExecutor

use of org.kie.pmml.pmml_4_2.PMMLExecutor in project drools by kiegroup.

the class ScorecardTest method testScorecardWithSimpleSetPredicateWithSpaceValue.

@Test
public void testScorecardWithSimpleSetPredicateWithSpaceValue() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_SIMPLE_SET_SPACE_VALUE_SCORECARD);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData requestData = new PMMLRequestData("123", "SimpleSetScorecardWithSpaceValue");
    requestData.addRequestParam("param", "optA");
    PMML4Result resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(13);
}
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 5 with PMMLExecutor

use of org.kie.pmml.pmml_4_2.PMMLExecutor in project drools by kiegroup.

the class ScorecardTest method testScorecardWithSimpleSetPredicate.

@Test
public void testScorecardWithSimpleSetPredicate() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_SIMPLE_SET_SCORECARD);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData requestData = new PMMLRequestData("123", "SimpleSetScorecard");
    requestData.addRequestParam("param1", 4);
    requestData.addRequestParam("param2", "optA");
    PMML4Result resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(113);
    requestData = new PMMLRequestData("123", "SimpleSetScorecard");
    requestData.addRequestParam("param1", 5);
    requestData.addRequestParam("param2", "optA");
    resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(33);
    requestData = new PMMLRequestData("123", "SimpleSetScorecard");
    requestData.addRequestParam("param1", -5);
    requestData.addRequestParam("param2", "optC");
    resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(123);
    requestData = new PMMLRequestData("123", "SimpleSetScorecard");
    requestData.addRequestParam("param1", -5);
    requestData.addRequestParam("param2", "optA");
    resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(113);
}
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)

Aggregations

Test (org.junit.Test)11 KieBase (org.kie.api.KieBase)11 PMML4Result (org.kie.api.pmml.PMML4Result)11 PMMLRequestData (org.kie.api.pmml.PMMLRequestData)11 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)11 PMMLExecutor (org.kie.pmml.pmml_4_2.PMMLExecutor)11 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2