use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class TreeEnsembleClassificationLearnerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
BufferedDataTable t = (BufferedDataTable) inObjects[0];
DataTableSpec spec = t.getDataTableSpec();
final FilterLearnColumnRearranger learnRearranger = m_configuration.filterLearnColumns(spec);
String warn = learnRearranger.getWarning();
BufferedDataTable learnTable = exec.createColumnRearrangeTable(t, learnRearranger, exec.createSubProgress(0.0));
DataTableSpec learnSpec = learnTable.getDataTableSpec();
TreeEnsembleModelPortObjectSpec ensembleSpec = m_configuration.createPortObjectSpec(learnSpec);
Map<String, DataCell> targetValueMap = ensembleSpec.getTargetColumnPossibleValueMap();
if (targetValueMap == null) {
throw new InvalidSettingsException("The target column does not " + "have possible values assigned. Most likely it " + "has too many different distinct values (learning an ID " + "column?) Fix it by preprocessing the table using " + "a \"Domain Calculator\".");
}
ExecutionMonitor readInExec = exec.createSubProgress(0.1);
ExecutionMonitor learnExec = exec.createSubProgress(0.8);
ExecutionMonitor outOfBagExec = exec.createSubProgress(0.1);
TreeDataCreator dataCreator = new TreeDataCreator(m_configuration, learnSpec, learnTable.getRowCount());
exec.setProgress("Reading data into memory");
TreeData data = dataCreator.readData(learnTable, m_configuration, readInExec);
m_hiliteRowSample = dataCreator.getDataRowsForHilite();
m_viewMessage = dataCreator.getViewMessage();
String dataCreationWarning = dataCreator.getAndClearWarningMessage();
if (dataCreationWarning != null) {
if (warn == null) {
warn = dataCreationWarning;
} else {
warn = warn + "\n" + dataCreationWarning;
}
}
readInExec.setProgress(1.0);
exec.setMessage("Learning trees");
TreeEnsembleLearner learner = new TreeEnsembleLearner(m_configuration, data);
TreeEnsembleModel model;
try {
model = learner.learnEnsemble(learnExec);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof Exception) {
throw (Exception) cause;
}
throw e;
}
TreeEnsembleModelPortObject modelPortObject = TreeEnsembleModelPortObject.createPortObject(ensembleSpec, model, exec.createFileStore(UUID.randomUUID().toString() + ""));
learnExec.setProgress(1.0);
exec.setMessage("Out of bag prediction");
TreeEnsemblePredictor outOfBagPredictor = createOutOfBagPredictor(ensembleSpec, modelPortObject, spec);
outOfBagPredictor.setOutofBagFilter(learner.getRowSamples(), data.getTargetColumn());
ColumnRearranger outOfBagRearranger = outOfBagPredictor.getPredictionRearranger();
BufferedDataTable outOfBagTable = exec.createColumnRearrangeTable(t, outOfBagRearranger, outOfBagExec);
BufferedDataTable colStatsTable = learner.createColumnStatisticTable(exec.createSubExecutionContext(0.0));
m_ensembleModelPortObject = modelPortObject;
if (warn != null) {
setWarningMessage(warn);
}
return new PortObject[] { outOfBagTable, colStatsTable, modelPortObject };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class DoubleToIntNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
List<String> inclcols = m_inclCols.getIncludeList();
if (inclcols.size() == 0) {
// nothing to convert, let's return the input table.
setWarningMessage("No columns selected," + " returning input DataTable.");
return new BufferedDataTable[] { inData[0] };
}
DataTableSpec inspec = inData[0].getDataTableSpec();
WarningMessage warningMessage = new WarningMessage();
int[] indices = findIndices(inspec, warningMessage);
ConverterFactory converterFac;
String calctype = m_calctype.getStringValue();
if (calctype.equals(CFG_CEIL)) {
converterFac = new CeilConverterFactory(indices, m_prodLong.getBooleanValue(), inspec, warningMessage);
} else if (calctype.equals(CFG_FLOOR)) {
converterFac = new FloorConverterFactory(indices, m_prodLong.getBooleanValue(), inspec, warningMessage);
} else {
converterFac = new ConverterFactory(indices, m_prodLong.getBooleanValue(), inspec, warningMessage);
}
ColumnRearranger colre = new ColumnRearranger(inspec);
colre.replace(converterFac, indices);
BufferedDataTable resultTable = exec.createColumnRearrangeTable(inData[0], colre, exec);
if (warningMessage.get() != null) {
setWarningMessage(warningMessage.get());
}
return new BufferedDataTable[] { resultTable };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class DoubleToIntNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
WarningMessage warningMessage = new WarningMessage();
int[] indices = findIndices(inSpecs[0], warningMessage);
if (warningMessage.get() != null) {
setWarningMessage(warningMessage.get());
}
ConverterFactory converterFac = new ConverterFactory(indices, m_prodLong.getBooleanValue(), inSpecs[0], warningMessage);
ColumnRearranger colre = new ColumnRearranger(inSpecs[0]);
colre.replace(converterFac, indices);
DataTableSpec newspec = colre.createSpec();
return new DataTableSpec[] { newspec };
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class DoubleToIntNodeModel method createColumnRearranger.
/**
* {@inheritDoc}
*
* @since 3.1
*/
@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec, final SimpleStreamableOperatorInternals emptyInternals) throws InvalidSettingsException {
WarningMessage warningMessage = (WarningMessage) emptyInternals;
int[] indices = findIndices(spec, warningMessage);
ConverterFactory converterFac;
String calctype = m_calctype.getStringValue();
if (calctype.equals(CFG_CEIL)) {
converterFac = new CeilConverterFactory(indices, m_prodLong.getBooleanValue(), spec, warningMessage);
} else if (calctype.equals(CFG_FLOOR)) {
converterFac = new FloorConverterFactory(indices, m_prodLong.getBooleanValue(), spec, warningMessage);
} else {
converterFac = new ConverterFactory(indices, m_prodLong.getBooleanValue(), spec, warningMessage);
}
ColumnRearranger colre = new ColumnRearranger(spec);
colre.replace(converterFac, indices);
return colre;
}
use of org.knime.core.data.container.ColumnRearranger in project knime-core by knime.
the class Many2OneColPMMLNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inDataSpec = (DataTableSpec) inSpecs[0];
if (m_includedColumns.getIncludeList().size() <= 0) {
setWarningMessage("No column selected. Node will have no effect!");
}
// if it is not a reg exp it must be double compatible
if (!m_includeMethod.getStringValue().equals(IncludeMethod.RegExpPattern.name())) {
for (String colName : m_includedColumns.getIncludeList()) {
if (!inDataSpec.getColumnSpec(colName).getType().isCompatible(DoubleValue.class)) {
throw new InvalidSettingsException("For selected include method '" + m_includeMethod.getStringValue() + "' only double compatible values are allowed." + " Column '" + colName + "' is not.");
}
}
}
ColumnRearranger rearranger = createRearranger(inDataSpec, getCellFactory(inDataSpec));
if (m_pmmlEnabled) {
PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inDataSpec);
return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
} else {
return new DataTableSpec[] { rearranger.createSpec() };
}
}
Aggregations