use of org.knime.base.node.mine.bayes.naivebayes.datamodel2.PMMLNaiveBayesModelTranslator in project knime-core by knime.
the class NaiveBayesLearnerNodeModel2 method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException {
LOGGER.debug("Entering execute of " + NaiveBayesLearnerNodeModel2.class.getName());
assert (inData != null && ((inData.length == 2 && m_pmmlInEnabled) || (inData.length == 1 && !m_pmmlInEnabled)) && inData[TRAINING_DATA_PORT] != null);
final PortObject inObject = inData[TRAINING_DATA_PORT];
if (!(inObject instanceof BufferedDataTable)) {
throw new IllegalArgumentException("Invalid input data");
}
final BufferedDataTable trainingTable = (BufferedDataTable) inObject;
final boolean ignoreMissingVals = m_ignoreMissingVals.getBooleanValue();
final boolean pmmlCompatible = m_pmmlCompatible.getBooleanValue();
final int maxNoOfNomVals = m_maxNoOfNominalVals.getIntValue();
m_model = new NaiveBayesModel(trainingTable, m_classifyColumnName.getStringValue(), exec, maxNoOfNomVals, ignoreMissingVals, pmmlCompatible, m_threshold.getDoubleValue());
final List<String> missingModels = m_model.getAttributesWithMissingVals();
if (missingModels.size() > 0) {
final StringBuilder buf = new StringBuilder();
buf.append("The following attributes contain missing values: ");
for (int i = 0, length = missingModels.size(); i < length; i++) {
if (i != 0) {
buf.append(", ");
}
if (i > 3) {
buf.append("...(see View)");
break;
}
buf.append(missingModels.get(i));
}
setWarningMessage(buf.toString());
}
if (m_model.containsSkippedAttributes()) {
setWarningMessage(m_model.getSkippedAttributesString(3));
}
LOGGER.debug("Exiting execute of " + NaiveBayesLearnerNodeModel2.class.getName());
// handle the optional PMML input
final PMMLPortObject inPMMLPort = m_pmmlInEnabled ? (PMMLPortObject) inData[MODEL_INPORT] : null;
final DataTableSpec tableSpec = trainingTable.getSpec();
final PMMLPortObjectSpec outPortSpec = createPMMLSpec(tableSpec, inPMMLPort == null ? null : inPMMLPort.getSpec(), m_model.getPMMLLearningCols(), m_model.getClassColumnName());
final PMMLPortObject outPMMLPort = new PMMLPortObject(outPortSpec, inPMMLPort, tableSpec);
outPMMLPort.addModelTranslater(new PMMLNaiveBayesModelTranslator(m_model));
return new PortObject[] { outPMMLPort, m_model.getStatisticsTable() };
}
use of org.knime.base.node.mine.bayes.naivebayes.datamodel2.PMMLNaiveBayesModelTranslator in project knime-core by knime.
the class NaiveBayesPredictorNodeModel2 method createColumnRearranger.
/* Helper to create the column rearranger that does the actual work */
private ColumnRearranger createColumnRearranger(final PMMLPortObject pmmlPortObj, final DataTableSpec inSpec) {
final PMMLNaiveBayesModelTranslator translator = new PMMLNaiveBayesModelTranslator();
pmmlPortObj.initializeModelTranslator(translator);
final NaiveBayesModel model = translator.getModel();
PredictorHelper predictorHelper = PredictorHelper.getInstance();
final String classColumnName = model.getClassColumnName();
final String predictionColName = m_overridePredicted.getBooleanValue() ? m_predictionColumnName.getStringValue() : predictorHelper.computePredictionDefault(classColumnName);
final NaiveBayesCellFactory appender = new NaiveBayesCellFactory(model, predictionColName, inSpec, m_inclProbVals.getBooleanValue(), m_probabilitySuffix.getStringValue());
final ColumnRearranger rearranger = new ColumnRearranger(inSpec);
rearranger.append(appender);
return rearranger;
}
Aggregations