use of org.dmg.pmml.pmml_4_2.descr.Scorecard in project drools by kiegroup.
the class PMML4Compiler method checkBuildingResources.
private static KieBase checkBuildingResources(PMML pmml) throws IOException {
KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = ks.getKieClasspathContainer();
if (registry == null) {
initRegistry();
}
String chosenKieBase = null;
for (Object o : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
if (o instanceof NaiveBayesModel) {
if (!naiveBayesLoaded) {
for (String ntempl : NAIVE_BAYES_TEMPLATES) {
prepareTemplate(ntempl);
}
naiveBayesLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "PMML-Bayes" : "PMML";
}
if (o instanceof NeuralNetwork) {
if (!neuralLoaded) {
for (String ntempl : NEURAL_TEMPLATES) {
prepareTemplate(ntempl);
}
neuralLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "PMML-Neural" : "PMML";
}
if (o instanceof ClusteringModel) {
if (!clusteringLoaded) {
for (String ntempl : CLUSTERING_TEMPLATES) {
prepareTemplate(ntempl);
}
clusteringLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "PMML-Cluster" : "PMML";
}
if (o instanceof SupportVectorMachineModel) {
if (!svmLoaded) {
for (String ntempl : SVM_TEMPLATES) {
prepareTemplate(ntempl);
}
svmLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "PMML-SVM" : "PMML";
}
if (o instanceof TreeModel) {
if (!treeLoaded) {
for (String ntempl : TREE_TEMPLATES) {
prepareTemplate(ntempl);
}
treeLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "PMML-Tree" : "PMML";
}
if (o instanceof RegressionModel) {
if (!simpleRegLoaded) {
for (String ntempl : SIMPLEREG_TEMPLATES) {
prepareTemplate(ntempl);
}
simpleRegLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "PMML-Regression" : "PMML";
}
if (o instanceof Scorecard) {
if (!scorecardLoaded) {
for (String ntempl : SCORECARD_TEMPLATES) {
prepareTemplate(ntempl);
}
scorecardLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "PMML-Scorecard" : "PMML";
}
}
if (chosenKieBase == null) {
chosenKieBase = "PMML-Base";
}
return kieContainer.getKieBase(chosenKieBase);
}
use of org.dmg.pmml.pmml_4_2.descr.Scorecard in project drools by kiegroup.
the class ExternalObjectModelTest method testPMMLCustomOutput.
@Test
public void testPMMLCustomOutput() throws Exception {
PMML pmmlDocument = null;
String drl = null;
if (scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_externalmodel.xls"))) {
pmmlDocument = scorecardCompiler.getPMMLDocument();
assertNotNull(pmmlDocument);
PMML4Compiler.dumpModel(pmmlDocument, System.out);
drl = scorecardCompiler.getDRL();
assertTrue(drl != null && !drl.isEmpty());
// System.out.println(drl);
} else {
fail("failed to parse scoremodel Excel.");
}
for (Object serializable : pmmlDocument.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
if (serializable instanceof Scorecard) {
Scorecard scorecard = (Scorecard) serializable;
for (Object obj : scorecard.getExtensionsAndCharacteristicsAndMiningSchemas()) {
if (obj instanceof Output) {
Output output = (Output) obj;
final List<OutputField> outputFields = output.getOutputFields();
assertEquals(1, outputFields.size());
final OutputField outputField = outputFields.get(0);
assertNotNull(outputField);
assertEquals("totalScore", outputField.getName());
assertEquals("Final Score", outputField.getDisplayName());
assertEquals("double", outputField.getDataType().value());
assertEquals("predictedValue", outputField.getFeature().value());
final Extension extension = ScorecardPMMLUtils.getExtension(outputField.getExtensions(), PMMLExtensionNames.EXTERNAL_CLASS);
assertNotNull(extension);
assertEquals("org.drools.scorecards.example.Applicant", extension.getValue());
return;
}
}
}
}
fail();
}
use of org.dmg.pmml.pmml_4_2.descr.Scorecard in project drools by kiegroup.
the class ScorecardReasonCodeTest method testUseReasonCodes.
@Test
public void testUseReasonCodes() throws Exception {
final ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
boolean compileResult = scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_reasoncodes.xls"));
if (!compileResult) {
assertErrors(scorecardCompiler);
}
final PMML pmmlDocument = scorecardCompiler.getPMMLDocument();
for (Object serializable : pmmlDocument.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
if (serializable instanceof Scorecard) {
assertTrue(((Scorecard) serializable).getUseReasonCodes());
assertEquals(100.0, ((Scorecard) serializable).getInitialScore(), 0.0);
assertEquals("pointsBelow", ((Scorecard) serializable).getReasonCodeAlgorithm());
}
}
}
use of org.dmg.pmml.pmml_4_2.descr.Scorecard in project drools by kiegroup.
the class ScorecardReasonCodeTest method testBaselineScores.
@Test
public void testBaselineScores() throws Exception {
ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
boolean compileResult = scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_reasoncodes.xls"));
if (!compileResult) {
assertErrors(scorecardCompiler);
}
final PMML pmmlDocument = scorecardCompiler.getPMMLDocument();
for (Object serializable : pmmlDocument.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
if (serializable instanceof Scorecard) {
for (Object obj : ((Scorecard) serializable).getExtensionsAndCharacteristicsAndMiningSchemas()) {
if (obj instanceof Characteristics) {
Characteristics characteristics = (Characteristics) obj;
assertEquals(4, characteristics.getCharacteristics().size());
assertEquals(10.0, characteristics.getCharacteristics().get(0).getBaselineScore(), 0.0);
assertEquals(99.0, characteristics.getCharacteristics().get(1).getBaselineScore(), 0.0);
assertEquals(12.0, characteristics.getCharacteristics().get(2).getBaselineScore(), 0.0);
assertEquals(15.0, characteristics.getCharacteristics().get(3).getBaselineScore(), 0.0);
assertEquals(25.0, ((Scorecard) serializable).getBaselineScore(), 0.0);
return;
}
}
}
}
fail();
}
use of org.dmg.pmml.pmml_4_2.descr.Scorecard in project drools by kiegroup.
the class ScorecardReasonCodeTest method testAbsenceOfReasonCodes.
@Test
public void testAbsenceOfReasonCodes() throws Exception {
ScorecardCompiler scorecardCompiler = new ScorecardCompiler(INTERNAL_DECLARED_TYPES);
scorecardCompiler.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_c.xls"));
PMML pmml = scorecardCompiler.getPMMLDocument();
for (Object serializable : pmml.getAssociationModelsAndBaselineModelsAndClusteringModels()) {
if (serializable instanceof Scorecard) {
assertFalse(((Scorecard) serializable).getUseReasonCodes());
}
}
}
Aggregations