Search in sources :

Example 81 with ColumnRearranger

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) TreeEnsembleModel(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModel) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) TreeEnsembleLearner(org.knime.base.node.mine.treeensemble2.learner.TreeEnsembleLearner) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) DataCell(org.knime.core.data.DataCell) TreeData(org.knime.base.node.mine.treeensemble2.data.TreeData) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) ExecutionException(java.util.concurrent.ExecutionException) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictor) TreeDataCreator(org.knime.base.node.mine.treeensemble2.data.TreeDataCreator) TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObject) PortObject(org.knime.core.node.port.PortObject)

Example 82 with ColumnRearranger

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 83 with ColumnRearranger

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger)

Example 84 with ColumnRearranger

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;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 85 with ColumnRearranger

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() };
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DoubleValue(org.knime.core.data.DoubleValue) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Aggregations

ColumnRearranger (org.knime.core.data.container.ColumnRearranger)393 DataTableSpec (org.knime.core.data.DataTableSpec)221 BufferedDataTable (org.knime.core.node.BufferedDataTable)153 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 DataColumnSpec (org.knime.core.data.DataColumnSpec)116 DataRow (org.knime.core.data.DataRow)79 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)69 DataCell (org.knime.core.data.DataCell)63 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)55 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)49 ExecutionContext (org.knime.core.node.ExecutionContext)46 PortObject (org.knime.core.node.port.PortObject)39 ArrayList (java.util.ArrayList)38 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)36 DataType (org.knime.core.data.DataType)34 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)32 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)27 DoubleValue (org.knime.core.data.DoubleValue)26 SettingsModelFilterString (org.knime.core.node.defaultnodesettings.SettingsModelFilterString)26 TreeEnsembleModelPortObjectSpec (org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)25