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);
}
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");
}
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();
}
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();
}
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);
}
Aggregations