use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class RegressionTreeLearnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// guaranteed to not be null (according to API)
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
if (m_configuration == null) {
throw new InvalidSettingsException("No configuration available");
}
final FilterLearnColumnRearranger learnRearranger = m_configuration.filterLearnColumns(inSpec);
final String warn = learnRearranger.getWarning();
if (warn != null) {
setWarningMessage(warn);
}
DataTableSpec learnSpec = learnRearranger.createSpec();
RegressionTreeModelPortObjectSpec treeSpec = new RegressionTreeModelPortObjectSpec(learnSpec);
return new PortObjectSpec[] { treeSpec };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class TreeEnsembleShrinkerNodeModel method configure.
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
TreeEnsembleModelPortObjectSpec modelSpec = (TreeEnsembleModelPortObjectSpec) inSpecs[0];
modelSpec.assertTargetTypeMatches(false);
DataTableSpec tableSpec = (DataTableSpec) inSpecs[1];
int targetColumnIndex = tableSpec.findColumnIndex(m_config.getTargetColumn());
if (targetColumnIndex < 0 || !tableSpec.getColumnSpec(targetColumnIndex).getType().isCompatible(StringValue.class)) {
throw new InvalidSettingsException("No valid target column selected");
}
return new PortObjectSpec[] { null };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class GradientBoostingClassificationLearnerNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// guaranteed to not be null (according to API)
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
if (m_configuration == null) {
throw new InvalidSettingsException("No configuration available");
}
final FilterLearnColumnRearranger learnRearranger = m_configuration.filterLearnColumns(inSpec);
// final String warn = learnRearranger.getWarning();
// if (warn != null) {
// setWarningMessage(warn);
// }
m_configuration.checkColumnSelection(inSpec);
DataTableSpec learnSpec = learnRearranger.createSpec();
TreeEnsembleModelPortObjectSpec ensembleSpec = m_configuration.createPortObjectSpec(learnSpec);
ensembleSpec.assertTargetTypeMatches(false);
// the following call may return null, which is OK during configure
// but not upon execution (spec may not be populated yet, e.g.
// predecessor not executed)
// if the possible values is not null, the following call checks
// for duplicates in the toString() representation
ensembleSpec.getTargetColumnPossibleValueMap();
return new PortObjectSpec[] { ensembleSpec };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class NaiveBayesPredictorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
// check the input data
assert (inSpecs != null && inSpecs.length == 2 && inSpecs[DATA_IN_PORT] != null && inSpecs[MODEL_IN_PORT] != null);
final PortObjectSpec modelObject = inSpecs[MODEL_IN_PORT];
if (!(modelObject instanceof NaiveBayesPortObjectSpec)) {
throw new IllegalArgumentException("Invalid input data");
}
final DataTableSpec trainingSpec = ((NaiveBayesPortObjectSpec) modelObject).getTableSpec();
final DataColumnSpec classColumn = ((NaiveBayesPortObjectSpec) modelObject).getClassColumn();
if (trainingSpec == null) {
throw new InvalidSettingsException("No model spec available");
}
final PortObjectSpec inSpec = inSpecs[DATA_IN_PORT];
if (!(inSpec instanceof DataTableSpec)) {
throw new IllegalArgumentException("TableSpec must not be null");
}
final DataTableSpec spec = (DataTableSpec) inSpec;
// check the input data for columns with the wrong name or wrong type
final List<String> unknownCols = check4UnknownCols(trainingSpec, spec);
if (unknownCols.size() >= spec.getNumColumns()) {
setWarningMessage("No known attribute columns found use " + "class prior probability to predict the class membership");
} else if (unknownCols.size() == 1) {
setWarningMessage("Input column " + unknownCols.get(0) + " is unknown and will be skipped.");
} else if (unknownCols.size() > 1) {
final StringBuilder buf = new StringBuilder();
buf.append("The following input columns are unknown and " + "will be skipped: ");
for (int i = 0, length = unknownCols.size(); i < length; i++) {
if (i != 0) {
buf.append(", ");
}
if (i > 3) {
buf.append("...");
break;
}
buf.append(unknownCols.get(i));
}
setWarningMessage(buf.toString());
}
// check if the learned model contains columns which are not in the
// input data
final List<String> missingInputCols = check4MissingCols(trainingSpec, classColumn.getName(), spec);
if (missingInputCols.size() == 1) {
setWarningMessage("Attribute " + missingInputCols.get(0) + " is missing in the input data");
} else if (missingInputCols.size() > 1) {
final StringBuilder buf = new StringBuilder();
buf.append("The following attributes are missing in " + "the input data: ");
for (int i = 0, length = missingInputCols.size(); i < length; i++) {
if (i != 0) {
buf.append(", ");
}
if (i > 3) {
buf.append("...");
break;
}
buf.append(missingInputCols.get(i));
}
setWarningMessage(buf.toString());
}
final PredictorHelper predictorHelper = PredictorHelper.getInstance();
final DataColumnSpec resultColSpecs = NaiveBayesCellFactory.createResultColSpecs(predictorHelper.computePredictionColumnName(m_predictionColumnName.getStringValue(), m_overridePredicted.getBooleanValue(), classColumn.getName()), classColumn.getType(), spec, m_inclProbVals.getBooleanValue());
if (resultColSpecs != null) {
return new PortObjectSpec[] { AppendedColumnTable.getTableSpec(spec, resultColSpecs) };
}
return null;
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class DecTreePredictorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
PMMLPortObjectSpec treeSpec = (PMMLPortObjectSpec) inSpecs[INMODELPORT];
DataTableSpec inSpec = (DataTableSpec) inSpecs[1];
for (String learnColName : treeSpec.getLearningFields()) {
if (!inSpec.containsName(learnColName)) {
throw new InvalidSettingsException("Learning column \"" + learnColName + "\" not found in input " + "data to be predicted");
}
}
return new PortObjectSpec[] { createOutTableSpec(inSpecs) };
}
Aggregations