use of org.kie.pmml.pmml_4_2.model.ScoreCard 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.model.ScoreCard 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);
}
use of org.kie.pmml.pmml_4_2.model.ScoreCard in project drools by kiegroup.
the class ScorecardTest method testScorecard.
@Test
public void testScorecard() throws Exception {
RuleUnitExecutor executor = createExecutor(source1);
PMMLRequestData requestData = createRequest("123", "Sample Score", 33.0, "SKYDIVER", "KN", true);
PMML4Result resultHolder = new PMML4Result();
List<String> possiblePackages = calculatePossiblePackageNames("Sample Score", "org.drools.scorecards.example");
Class<? extends RuleUnit> unitClass = getStartingRuleUnit("RuleUnitIndicator", (InternalKnowledgeBase) kbase, possiblePackages);
assertNotNull(unitClass);
executor.run(unitClass);
Collection<? extends EntryPoint> eps = ((InternalRuleUnitExecutor) executor).getKieSession().getEntryPoints();
eps.forEach(ep -> {
System.out.println(ep);
});
data.insert(requestData);
resultData.insert(resultHolder);
executor.run(unitClass);
assertEquals(3, resultHolder.getResultVariables().size());
Object scorecard = resultHolder.getResultValue("ScoreCard", null);
assertNotNull(scorecard);
Double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).orElse(null);
assertEquals(41.345, score, 0.000);
Object ranking = resultHolder.getResultValue("ScoreCard", "ranking");
assertNotNull(ranking);
assertTrue(ranking instanceof LinkedHashMap);
LinkedHashMap map = (LinkedHashMap) ranking;
assertTrue(map.containsKey("LX00"));
assertTrue(map.containsKey("RES"));
assertTrue(map.containsKey("CX2"));
assertEquals(-1.0, map.get("LX00"));
assertEquals(-10.0, map.get("RES"));
assertEquals(-30.0, map.get("CX2"));
Iterator iter = map.keySet().iterator();
assertEquals("LX00", iter.next());
assertEquals("RES", iter.next());
assertEquals("CX2", iter.next());
}
use of org.kie.pmml.pmml_4_2.model.ScoreCard in project drools by kiegroup.
the class ScorecardTest method testScorecardWithCompoundPredicate.
@Test
public void testScorecardWithCompoundPredicate() {
KieBase kieBase = PMMLKieBaseUtil.createKieBaseWithPMML(SOURCE_COMPOUND_PREDICATE_SCORECARD);
PMMLExecutor executor = new PMMLExecutor(kieBase);
PMMLRequestData requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
requestData.addRequestParam("param1", 41.0);
requestData.addRequestParam("param2", 21.0);
PMML4Result resultHolder = executor.run(requestData);
double score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(120.8);
Map<String, Double> rankingMap = (Map<String, Double>) resultHolder.getResultValue("ScoreCard", "ranking");
Assertions.assertThat(rankingMap.get("reasonCh1")).isEqualTo(50);
Assertions.assertThat(rankingMap.get("reasonCh2")).isEqualTo(5);
requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
requestData.addRequestParam("param1", 40.0);
requestData.addRequestParam("param2", 25.0);
resultHolder = executor.run(requestData);
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(120.8);
requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
requestData.addRequestParam("param1", 40.0);
requestData.addRequestParam("param2", 55.0);
resultHolder = executor.run(requestData);
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(210.8);
requestData = new PMMLRequestData("123", "ScorecardCompoundPredicate");
requestData.addRequestParam("param1", 4.0);
requestData.addRequestParam("param2", -25.0);
resultHolder = executor.run(requestData);
score = resultHolder.getResultValue("ScoreCard", "score", Double.class).get();
Assertions.assertThat(score).isEqualTo(30.8);
}
use of org.kie.pmml.pmml_4_2.model.ScoreCard in project drools by kiegroup.
the class PMML4ModelFactory method getModel.
public PMML4Model getModel(Segment segment, MiningSegmentation segmentation) {
PMML4Model model = null;
if (segment.getMiningModel() != null) {
MiningModel mm = segment.getMiningModel();
model = new Miningmodel(mm.getModelName(), mm, segmentation.getOwner(), null);
} else if (segment.getRegressionModel() != null) {
RegressionModel rm = segment.getRegressionModel();
model = new Regression(rm.getModelName(), rm, segmentation.getOwner(), null);
} else if (segment.getScorecard() != null) {
Scorecard sc = segment.getScorecard();
model = new ScorecardModel(sc.getModelName(), sc, segmentation.getOwner(), null);
} else if (segment.getTreeModel() != null) {
TreeModel tm = segment.getTreeModel();
model = new Treemodel(tm.getModelName(), tm, segmentation.getOwner(), null);
}
return model;
}
Aggregations