use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class GradientBoostingPredictorNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
GradientBoostingModelPortObject model = (GradientBoostingModelPortObject) ((PortObjectInput) inputs[0]).getPortObject();
TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final GradientBoostingPredictor<GradientBoostedTreesModel> pred = new GradientBoostingPredictor<>((GradientBoostedTreesModel) model.getEnsembleModel(), modelSpec, dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
StreamableFunction func = rearranger.createStreamableFunction(1, 0);
func.runFinal(inputs, outputs, exec);
}
};
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class GradientBoostingPredictorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
GradientBoostingModelPortObject model = (GradientBoostingModelPortObject) inObjects[0];
TreeEnsembleModelPortObjectSpec modelSpec = model.getSpec();
BufferedDataTable data = (BufferedDataTable) inObjects[1];
DataTableSpec dataSpec = data.getDataTableSpec();
final GradientBoostingPredictor<GradientBoostedTreesModel> pred = new GradientBoostingPredictor<>((GradientBoostedTreesModel) model.getEnsembleModel(), modelSpec, dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
BufferedDataTable outTable = exec.createColumnRearrangeTable(data, rearranger, exec);
return new BufferedDataTable[] { outTable };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class AttributeSelectionPanel method removeColumn.
private static DataTableSpec removeColumn(final DataTableSpec spec, final String col) {
ColumnRearranger r = new ColumnRearranger(spec);
r.remove(col);
return r.createSpec();
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class AttributeSelectionPanel method getMissingColSpecName.
@SuppressWarnings("null")
private static String getMissingColSpecName(final DataTableSpec spec, final String[] includedNames, final String[] excludedNames) {
ColumnRearranger r = new ColumnRearranger(spec);
// remove columns we know from the include list
for (String colName : includedNames) {
if (spec.containsName(colName)) {
r.remove(colName);
}
}
// remove columns we know from the exclude list
for (String colName : excludedNames) {
if (spec.containsName(colName)) {
r.remove(colName);
}
}
DataTableSpec tableSpecWithMissing = r.createSpec();
DataColumnSpec formerTargetSpec = null;
// were either in the include or exclude list
for (DataColumnSpec colSpec : tableSpecWithMissing) {
DataType colType = colSpec.getType();
if (colType.isCompatible(NominalValue.class) || colType.isCompatible(DoubleValue.class)) {
formerTargetSpec = colSpec;
break;
}
}
assert formerTargetSpec != null : "The former target spec is no longer part of the table, please check.";
return formerTargetSpec.getName();
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class TreeEnsembleClassificationLearnerNodeModel 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 };
}
Aggregations