use of org.kie.api.pmml.PMML4Result in project drools by kiegroup.
the class MiningmodelTest method testWithScorecard.
@Test
public void testWithScorecard() {
RuleUnitExecutor executor = createExecutor(source2);
// KieRuntimeLogger console = ((InternalRuleUnitExecutor)executor).addConsoleLogger();
PMMLRequestData request = new PMMLRequestData("1234", "SampleScorecardMine");
request.addRequestParam("age", 33.0);
request.addRequestParam("occupation", "SKYDIVER");
request.addRequestParam("residenceState", "KN");
request.addRequestParam("validLicense", true);
PMML4Result resultHolder = new PMML4Result();
resultHolder.setCorrelationId(request.getCorrelationId());
DataSource<PMMLRequestData> childModelRequest = executor.newDataSource("childModelRequest");
DataSource<PMML4Result> childModelResults = executor.newDataSource("childModelResults");
DataSource<SegmentExecution> childModelSegments = executor.newDataSource("childModelSegments");
DataSource<? extends AbstractPMMLData> miningModelPojo = executor.newDataSource("miningModelPojo");
List<String> possiblePackages = this.calculatePossiblePackageNames("SampleScorecardMine");
Class<? extends RuleUnit> ruleUnitClass = this.getStartingRuleUnit("Start Mining - SampleScorecardMine", (InternalKnowledgeBase) kbase, possiblePackages);
assertNotNull(ruleUnitClass);
data.insert(request);
resultData.insert(resultHolder);
executor.run(ruleUnitClass);
// console.close();
resultData.forEach(rd -> {
assertEquals(request.getCorrelationId(), rd.getCorrelationId());
assertEquals("OK", rd.getResultCode());
if (rd.getSegmentationId() == null) {
ScoreCard sc = rd.getResultValue("ScoreCard", null, ScoreCard.class).orElse(null);
assertNotNull(sc);
Map map = sc.getRanking();
assertNotNull(map);
assertTrue(map instanceof LinkedHashMap);
LinkedHashMap ranking = (LinkedHashMap) map;
assertTrue(ranking.containsKey("LX00"));
assertTrue(ranking.containsKey("RES"));
assertTrue(ranking.containsKey("CX2"));
assertEquals(-1.0, ranking.get("LX00"));
assertEquals(-10.0, ranking.get("RES"));
assertEquals(-30.0, ranking.get("CX2"));
Iterator iter = ranking.keySet().iterator();
assertEquals("LX00", iter.next());
assertEquals("RES", iter.next());
assertEquals("CX2", iter.next());
}
});
int segmentsExecuted = 0;
for (Iterator<SegmentExecution> iter = childModelSegments.iterator(); iter.hasNext(); ) {
SegmentExecution cms = iter.next();
assertEquals(request.getCorrelationId(), cms.getCorrelationId());
if (cms.getState() == SegmentExecutionState.COMPLETE)
segmentsExecuted++;
}
assertEquals(1, segmentsExecuted);
}
use of org.kie.api.pmml.PMML4Result 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);
}
use of org.kie.api.pmml.PMML4Result 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);
}
use of org.kie.api.pmml.PMML4Result 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.api.pmml.PMML4Result in project drools by kiegroup.
the class SimpleRegressionTest method testClassification.
@Test
public void testClassification() throws Exception {
RuleUnitExecutor executor = createExecutor(source2);
PMMLRequestData request = new PMMLRequestData("123", "LinReg");
request.addRequestParam("fld1", 1.0);
request.addRequestParam("fld2", 1.0);
request.addRequestParam("fld3", "x");
PMML4Result resultHolder = new PMML4Result();
List<String> possiblePackages = calculatePossiblePackageNames("LinReg");
Class<? extends RuleUnit> unitClass = getStartingRuleUnit("RuleUnitIndicator", (InternalKnowledgeBase) kbase, possiblePackages);
assertNotNull(unitClass);
int x = executor.run(unitClass);
data.insert(request);
resultData.insert(resultHolder);
executor.run(unitClass);
assertNotNull(resultHolder.getResultValue("RegOut", null));
assertNotNull(resultHolder.getResultValue("RegProb", null));
assertNotNull(resultHolder.getResultValue("RegProbA", null));
String regOut = resultHolder.getResultValue("RegOut", "value", String.class).orElse(null);
Double regProb = resultHolder.getResultValue("RegProb", "value", Double.class).orElse(null);
Double regProbA = resultHolder.getResultValue("RegProbA", "value", Double.class).orElse(null);
assertEquals("catC", regOut);
assertEquals(0.709228, regProb, 1e-6);
assertEquals(0.010635, regProbA, 1e-6);
}
Aggregations