Search in sources :

Example 6 with PMMLExecutor

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

the class ScorecardTest method testScorecardWithComplexPartialScore.

@Test
public void testScorecardWithComplexPartialScore() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_COMPLEX_PARTIAL_SCORE_SCORECARD);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData requestData = new PMMLRequestData("123", "ComplexPartialScoreScorecard");
    requestData.addRequestParam("param", 5.0);
    PMML4Result resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(20);
    requestData = new PMMLRequestData("123", "ComplexPartialScoreScorecard");
    requestData.addRequestParam("param", 40.0);
    resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(150);
    requestData = new PMMLRequestData("123", "ComplexPartialScoreScorecard");
    requestData.addRequestParam("param", 100.0);
    resultHolder = executor.run(requestData);
    Assertions.assertThat(resultHolder).isNotNull();
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(205);
}
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 7 with PMMLExecutor

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

the class DecisionTreeTest method testLastPredictionMissingValueStrategy.

@Test
public void testLastPredictionMissingValueStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_LAST_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();
    String targetValue = resultHolder.getResultValue("Fld3", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isEqualTo("tgtY");
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 100.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    targetValue = resultHolder.getResultValue("Fld3", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isEqualTo("tgtA");
}
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 8 with PMMLExecutor

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

the class DecisionTreeTest method testReturnNullNoTrueChildPredictionStrategy.

@Test
public void testReturnNullNoTrueChildPredictionStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_RETURN_NULL_NOTRUECHILD_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();
    Assertions.assertThat(resultHolder.getResultValue("Fld2", "value", String.class)).isEmpty();
}
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 9 with PMMLExecutor

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

the class DecisionTreeTest method testNullPredictionMissingValueStrategy.

@Test
public void testNullPredictionMissingValueStrategy() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(TREE_RETURN_NULL_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();
    String targetValue = resultHolder.getResultValue("Fld3", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isEqualTo("tgtY");
    request = new PMMLRequestData("123", "TreeTest");
    request.addRequestParam("fld1", 100.0);
    resultHolder = executor.run(request);
    Assertions.assertThat(resultHolder).isNotNull();
    targetValue = resultHolder.getResultValue("Fld3", "value", String.class).orElse(null);
    Assertions.assertThat(targetValue).isNull();
}
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 10 with PMMLExecutor

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

the class ScorecardTest method testSimpleScorecard.

@Test
public void testSimpleScorecard() {
    KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_SIMPLE_SCORECARD);
    PMMLExecutor executor = new PMMLExecutor(kieBase);
    PMMLRequestData requestData = new PMMLRequestData("123", "SimpleScorecard");
    requestData.addRequestParam("param1", 10.0);
    requestData.addRequestParam("param2", 15.0);
    PMML4Result resultHolder = executor.run(requestData);
    double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(40.8);
    Map<String, Double> rankingMap = (Map<String, Double>) resultHolder.getResultValue("ScoreCard", "ranking");
    Assertions.assertThat(rankingMap.get("reasonCh1")).isEqualTo(5);
    Assertions.assertThat(rankingMap.get("reasonCh2")).isEqualTo(-6);
    requestData = new PMMLRequestData("123", "SimpleScorecard");
    requestData.addRequestParam("param1", 51.0);
    requestData.addRequestParam("param2", 12.0);
    resultHolder = executor.run(requestData);
    score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
    Assertions.assertThat(score).isEqualTo(120.8);
    rankingMap = (Map<String, Double>) resultHolder.getResultValue("ScoreCard", "ranking");
    Assertions.assertThat(rankingMap.get("reasonCh1")).isEqualTo(-75);
    Assertions.assertThat(rankingMap.get("reasonCh2")).isEqualTo(-6);
}
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) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) 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