use of org.kie.dmg.pmml.pmml_4_2.descr.PMML 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.kie.dmg.pmml.pmml_4_2.descr.PMML 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());
}
}
}
use of org.kie.dmg.pmml.pmml_4_2.descr.PMML 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 ? "KiePMML-Bayes" : "KiePMML";
}
if (o instanceof NeuralNetwork) {
if (!neuralLoaded) {
for (String ntempl : NEURAL_TEMPLATES) {
prepareTemplate(ntempl);
}
neuralLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "KiePMML-Neural" : "KiePMML";
}
if (o instanceof ClusteringModel) {
if (!clusteringLoaded) {
for (String ntempl : CLUSTERING_TEMPLATES) {
prepareTemplate(ntempl);
}
clusteringLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "KiePMML-Cluster" : "KiePMML";
}
if (o instanceof SupportVectorMachineModel) {
if (!svmLoaded) {
for (String ntempl : SVM_TEMPLATES) {
prepareTemplate(ntempl);
}
svmLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "KiePMML-SVM" : "KiePMML";
}
if (o instanceof TreeModel) {
if (!treeLoaded) {
for (String ntempl : TREE_TEMPLATES) {
prepareTemplate(ntempl);
}
treeLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "KiePMML-Tree" : "KiePMML";
}
if (o instanceof RegressionModel) {
if (!simpleRegLoaded) {
for (String ntempl : SIMPLEREG_TEMPLATES) {
prepareTemplate(ntempl);
}
simpleRegLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "KiePMML-Regression" : "KiePMML";
}
if (o instanceof Scorecard) {
if (!scorecardLoaded) {
for (String ntempl : SCORECARD_TEMPLATES) {
prepareTemplate(ntempl);
}
scorecardLoaded = true;
}
chosenKieBase = chosenKieBase == null ? "KiePMML-Scorecard" : "KiePMML";
}
}
if (chosenKieBase == null) {
chosenKieBase = "KiePMML-Base";
}
return kieContainer.getKieBase(chosenKieBase);
}
use of org.kie.dmg.pmml.pmml_4_2.descr.PMML in project drools by kiegroup.
the class PMML4Compiler method loadModel.
/**
* Imports a PMML source file, returning a Java descriptor
* @param model the PMML package name (classes derived from a specific schema)
* @param source the name of the PMML resource storing the predictive model
* @return the Java Descriptor of the PMML resource
*/
public PMML loadModel(String model, InputStream source) {
try {
if (schema == null) {
visitorBuildResults.add(new PMMLWarning(ResourceFactory.newInputStreamResource(source), "Could not validate PMML document, schema not available"));
}
JAXBContext jc = JAXBContext.newInstance(model);
Unmarshaller unmarshaller = jc.createUnmarshaller();
if (schema != null) {
unmarshaller.setSchema(schema);
}
return (PMML) unmarshaller.unmarshal(source);
} catch (JAXBException e) {
this.results.add(new PMMLError(e.toString()));
return null;
}
}
use of org.kie.dmg.pmml.pmml_4_2.descr.PMML in project drools by kiegroup.
the class PMML4UnitImpl method initDataDictionaryMap.
/**
* Initializes the internal structure that holds data dictionary information.
* This initializer should be called prior to any other initializers, since
* many other structures may have a dependency on the data dictionary.
*/
private void initDataDictionaryMap() {
DataDictionary dd = rawPmml.getDataDictionary();
if (dd != null) {
dataDictionaryMap = new HashMap<>();
for (DataField dataField : dd.getDataFields()) {
PMMLDataField df = new PMMLDataField(dataField);
dataDictionaryMap.put(df.getName(), df);
}
} else {
throw new IllegalStateException("BRMS-PMML requires a data dictionary section in the definition file");
}
}
Aggregations