use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class OptionsPanel 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 OptionsPanel 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 RegressionTreePMMLPredictorNodeModel method translateSpec.
private RegressionTreeModelPortObjectSpec translateSpec(final PMMLPortObjectSpec pmmlSpec) {
DataTableSpec pmmlDataSpec = pmmlSpec.getDataTableSpec();
ColumnRearranger cr = new ColumnRearranger(pmmlDataSpec);
List<DataColumnSpec> targets = pmmlSpec.getTargetCols();
CheckUtils.checkArgument(!targets.isEmpty(), "The provided PMML does not declare a target field.");
CheckUtils.checkArgument(targets.size() == 1, "The provided PMML declares multiple target. " + "This behavior is currently not supported.");
cr.move(targets.get(0).getName(), pmmlDataSpec.getNumColumns());
return new RegressionTreeModelPortObjectSpec(cr.createSpec());
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class RegressionTreePMMLPredictorNodeModel 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 {
PMMLPortObject model = (PMMLPortObject) ((PortObjectInput) inputs[0]).getPortObject();
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
Pair<RegressionTreeModel, RegressionTreeModelPortObjectSpec> treeSpecPair = importModel(model);
final RegressionTreePredictor pred = new RegressionTreePredictor(treeSpecPair.getFirst(), treeSpecPair.getSecond(), 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 RegressionTreePredictorNodeModel 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 {
RegressionTreeModelPortObject model = (RegressionTreeModelPortObject) ((PortObjectInput) inputs[0]).getPortObject();
DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
final RegressionTreePredictor pred = new RegressionTreePredictor(model.getModel(), model.getSpec(), dataSpec, m_configuration);
ColumnRearranger rearranger = pred.getPredictionRearranger();
StreamableFunction func = rearranger.createStreamableFunction(1, 0);
func.runFinal(inputs, outputs, exec);
}
};
}
Aggregations