use of org.knime.base.node.mine.bayes.naivebayes.port.NaiveBayesPortObject in project knime-core by knime.
the class NaiveBayesPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
LOGGER.debug("Entering execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
// check input data
assert (inData != null && inData.length == 2 && inData[DATA_IN_PORT] != null && inData[MODEL_IN_PORT] != null);
final PortObject dataObject = inData[DATA_IN_PORT];
if (!(dataObject instanceof BufferedDataTable)) {
throw new IllegalArgumentException("Invalid input data");
}
final BufferedDataTable data = (BufferedDataTable) dataObject;
final PortObject modelObject = inData[MODEL_IN_PORT];
if (!(modelObject instanceof NaiveBayesPortObject)) {
throw new IllegalArgumentException("Invalid input data");
}
final NaiveBayesModel model = ((NaiveBayesPortObject) modelObject).getModel();
exec.setMessage("Classifying rows...");
if (model == null) {
throw new Exception("Node not properly configured. " + "No Naive Bayes Model available.");
}
final double laplaceCorrector = m_laplaceCorrector.getDoubleValue();
final NaiveBayesCellFactory appender = new NaiveBayesCellFactory(model, data.getDataTableSpec(), m_inclProbVals.getBooleanValue(), laplaceCorrector);
final ColumnRearranger rearranger = new ColumnRearranger(data.getDataTableSpec());
rearranger.append(appender);
final BufferedDataTable returnVal = exec.createColumnRearrangeTable(data, rearranger, exec);
LOGGER.debug("Exiting execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
return new PortObject[] { returnVal };
}
use of org.knime.base.node.mine.bayes.naivebayes.port.NaiveBayesPortObject in project knime-core by knime.
the class NaiveBayesLearnerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws CanceledExecutionException, InvalidSettingsException {
LOGGER.debug("Entering execute of " + NaiveBayesLearnerNodeModel.class.getName());
// check input data
assert (inData != null && inData.length == 1 && 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 String colName = m_classifyColumnName.getStringValue();
final boolean ignoreMissingVals = m_ignoreMissingVals.getBooleanValue();
final int maxNoOfNomVals = m_maxNoOfNominalVals.getIntValue();
m_model = new NaiveBayesModel(trainingTable, colName, exec, maxNoOfNomVals, ignoreMissingVals);
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 " + NaiveBayesLearnerNodeModel.class.getName());
// return no data tables (empty array)
return new PortObject[] { new NaiveBayesPortObject(trainingTable.getDataTableSpec(), m_model) };
}
use of org.knime.base.node.mine.bayes.naivebayes.port.NaiveBayesPortObject in project knime-core by knime.
the class NaiveBayesPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
LOGGER.debug("Entering execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
// check input data
assert (inData != null && inData.length == 2 && inData[DATA_IN_PORT] != null && inData[MODEL_IN_PORT] != null);
final PortObject dataObject = inData[DATA_IN_PORT];
if (!(dataObject instanceof BufferedDataTable)) {
throw new IllegalArgumentException("Invalid input data");
}
final BufferedDataTable data = (BufferedDataTable) dataObject;
final PortObject modelObject = inData[MODEL_IN_PORT];
if (!(modelObject instanceof NaiveBayesPortObject)) {
throw new IllegalArgumentException("Invalid input data");
}
final NaiveBayesModel model = ((NaiveBayesPortObject) modelObject).getModel();
exec.setMessage("Classifying rows...");
if (model == null) {
throw new Exception("Node not properly configured. " + "No Naive Bayes Model available.");
}
final double laplaceCorrector = m_laplaceCorrector.getDoubleValue();
PredictorHelper predictorHelper = PredictorHelper.getInstance();
String classColumnName = model.getClassColumnName();
String predictionColName = m_overridePredicted.getBooleanValue() ? m_predictionColumnName.getStringValue() : predictorHelper.computePredictionDefault(classColumnName);
final NaiveBayesCellFactory appender = new NaiveBayesCellFactory(model, predictionColName, data.getDataTableSpec(), m_inclProbVals.getBooleanValue(), laplaceCorrector, m_probabilitySuffix.getStringValue());
final ColumnRearranger rearranger = new ColumnRearranger(data.getDataTableSpec());
rearranger.append(appender);
final BufferedDataTable returnVal = exec.createColumnRearrangeTable(data, rearranger, exec);
LOGGER.debug("Exiting execute(inData, exec) of class " + "NaiveBayesPredictorNodeModel.");
return new PortObject[] { returnVal };
}
Aggregations