use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class CategoryToNumberNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
List<String> inputCols = new ArrayList<String>();
for (DataColumnSpec column : inSpec) {
if (column.getType().isCompatible(StringValue.class)) {
inputCols.add(column.getName());
}
}
// Auto configuration when included columns are not set
if (null == m_settings.getIncludedColumns()) {
// when there is no column with nominal data
if (inputCols.isEmpty()) {
throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
} else {
// auto-configure
m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
}
} else {
if (!m_settings.getIncludeAll()) {
if (m_settings.getIncludedColumns().length == 0) {
setWarningMessage("No columns selected.");
}
List<String> included = new ArrayList<String>();
included.addAll(Arrays.asList(m_settings.getIncludedColumns()));
included.removeAll(inputCols);
if (!included.isEmpty()) {
// output first missing column
throw new InvalidSettingsException("Missing column: " + included.get(0).toString());
}
} else {
if (inputCols.isEmpty()) {
throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
} else {
// automatically add all columns
m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
}
}
}
ColumnRearranger rearranger = createRearranger(inSpec);
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
pmmlSpecCreator.addPreprocColNames(inputCols);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.
the class RandomForestClassificationLearnerNodeModel 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);
// 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();
final TreeEnsemblePredictor outOfBagPredictor = createOutOfBagPredictor(ensembleSpec, null, inSpec);
ColumnRearranger outOfBagRearranger = outOfBagPredictor.getPredictionRearranger();
DataTableSpec outOfBagSpec = outOfBagRearranger == null ? null : outOfBagRearranger.createSpec();
DataTableSpec colStatsSpec = TreeEnsembleLearner.getColumnStatisticTableSpec();
return new PortObjectSpec[] { outOfBagSpec, colStatsSpec, ensembleSpec };
}
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);
}
m_configuration.checkColumnSelection(inSpec);
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 GradientBoostingRegressionLearnerNodeModel 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);
// 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 GradientBoostingPMMLPredictorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[0];
DataType targetType = extractTargetType(pmmlSpec);
if (m_isRegression && !targetType.isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("This node expects a regression model.");
} else if (!m_isRegression && !targetType.isCompatible(StringValue.class)) {
throw new InvalidSettingsException("This node expectes a classification model.");
}
try {
AbstractTreeModelPMMLTranslator.checkPMMLSpec(pmmlSpec);
} catch (IllegalArgumentException e) {
throw new InvalidSettingsException(e.getMessage());
}
TreeEnsembleModelPortObjectSpec modelSpec = translateSpec(pmmlSpec);
String targetColName = modelSpec.getTargetColumn().getName();
if (m_configuration == null) {
m_configuration = TreeEnsemblePredictorConfiguration.createDefault(m_isRegression, targetColName);
} else if (!m_configuration.isChangePredictionColumnName()) {
m_configuration.setPredictionColumnName(TreeEnsemblePredictorConfiguration.getPredictColumnName(targetColName));
}
modelSpec.assertTargetTypeMatches(m_isRegression);
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final GradientBoostingPredictor<GradientBoostedTreesModel> pred = new GradientBoostingPredictor<>(null, modelSpec, dataSpec, m_configuration);
return new PortObjectSpec[] { pred.getPredictionRearranger().createSpec() };
}
Aggregations