Search in sources :

Example 86 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class MLPPredictorNodeModel method configure.

/**
 * The additional columns are created based on the model which is loaded in
 * the execute-method. Therefore, new DataTableSpecs are not available until
 * execute has been called.
 *
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMMLPortObjectSpec modelspec = (PMMLPortObjectSpec) inSpecs[0];
    DataTableSpec testSpec = (DataTableSpec) inSpecs[1];
    List<DataColumnSpec> targetCols = modelspec.getTargetCols();
    if (targetCols.isEmpty()) {
        throw new InvalidSettingsException("The PMML model" + " does not specify a target column for the prediction.");
    }
    DataColumnSpec targetCol = targetCols.iterator().next();
    /*
         * Check consistency between model and inputs, find columns to work on.
         */
    for (String incol : modelspec.getLearningFields()) {
        if (!testSpec.containsName(incol)) {
            throw new InvalidSettingsException("Could not find " + incol + " in inputspec");
        }
    }
    m_columns = getLearningColumnIndices(testSpec, modelspec);
    MLPClassificationFactory mymlp;
    // Regression
    if (targetCol.getType().isCompatible(DoubleValue.class)) {
        mymlp = new MLPClassificationFactory(true, m_columns, targetCol);
    } else {
        // Classification
        mymlp = new MLPClassificationFactory(false, m_columns, targetCol);
    }
    ColumnRearranger colre = new ColumnRearranger(testSpec);
    colre.append(mymlp);
    return new DataTableSpec[] { colre.createSpec() };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 87 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class LinRegLearnerNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    // must check if there are at least two numeric columns
    int numColsCount = 0;
    DataTableSpec dts = (DataTableSpec) specs[0];
    for (DataColumnSpec c : dts) {
        if (c.getType().isCompatible(DoubleValue.class)) {
            numColsCount++;
            if (numColsCount >= 2) {
                break;
            }
        }
    }
    if (numColsCount < 2) {
        throw new NotConfigurableException("Too few numeric columns " + "(need at least 2): " + numColsCount);
    }
    boolean includeAll = settings.getBoolean(LinRegLearnerNodeModel.CFG_VARIATES_USE_ALL, false);
    String[] includes = settings.getStringArray(LinRegLearnerNodeModel.CFG_VARIATES, new String[0]);
    String target = settings.getString(LinRegLearnerNodeModel.CFG_TARGET, null);
    boolean isCalcError = settings.getBoolean(LinRegLearnerNodeModel.CFG_CALC_ERROR, true);
    int first = settings.getInt(LinRegLearnerNodeModel.CFG_FROMROW, 1);
    int count = settings.getInt(LinRegLearnerNodeModel.CFG_ROWCNT, 10000);
    m_selectionPanel.update(dts, target);
    m_filterPanel.setKeepAllSelected(includeAll);
    // if includes list is empty, put everything into the include list
    m_filterPanel.update(dts, includes.length == 0, includes);
    // must hide the target from filter panel
    // updating m_filterPanel first does not work as the first
    // element in the spec will always be in the exclude list.
    String selected = m_selectionPanel.getSelectedColumn();
    if (selected != null) {
        DataColumnSpec colSpec = dts.getColumnSpec(selected);
        m_filterPanel.hideColumns(colSpec);
    }
    m_isCalcErrorChecker.setSelected(isCalcError);
    m_firstSpinner.setValue(first);
    m_countSpinner.setValue(count);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Example 88 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class RegressionPredictorNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    RegressionPredictorSettings s = new RegressionPredictorSettings();
    s.loadSettingsForDialog(settings);
    m_hasCustomPredictionName.setSelected(s.getHasCustomPredictionName());
    PMMLPortObjectSpec portSpec = (PMMLPortObjectSpec) specs[0];
    DataTableSpec tableSpec = (DataTableSpec) specs[1];
    if (s.getCustomPredictionName() != null) {
        m_customPredictionName.setText(s.getCustomPredictionName());
    } else {
        try {
            DataColumnSpec[] outSpec = RegressionPredictorCellFactory.createColumnSpec(portSpec, tableSpec, new RegressionPredictorSettings());
            m_customPredictionName.setText(outSpec[outSpec.length - 1].getName());
        } catch (InvalidSettingsException e) {
        // Open dialog and give a chance define settings
        }
    }
    m_includeProbs.setSelected(s.getIncludeProbabilities());
    m_probColumnSuffix.setText(s.getPropColumnSuffix());
    updateEnableState();
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 89 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class RegressionPredictorNodeModel method adjustSpecOfRegressionPredictorTable.

private BufferedDataTable adjustSpecOfRegressionPredictorTable(final BufferedDataTable table, final PortObject[] inData, final ExecutionContext exec) throws InvalidSettingsException {
    String predColumn = determinPredictedColumName(inData);
    if (predColumn != null) {
        DataColumnSpec[] colSpecs = getColumnSpecs(table.getSpec());
        colSpecs[colSpecs.length - 1] = replaceNameOf(colSpecs[colSpecs.length - 1], predColumn);
        return exec.createSpecReplacerTable(table, new DataTableSpec(colSpecs));
    } else {
        return table;
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Example 90 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class RegressionPredictorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
public PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    PMMLPortObject port = (PMMLPortObject) inData[0];
    List<Node> models = port.getPMMLValue().getModels(PMMLModelType.GeneralRegressionModel);
    if (models.isEmpty()) {
        LOGGER.warn("No regression models in the input PMML.");
        @SuppressWarnings("deprecation") org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel regrPredictor = new org.knime.base.node.mine.regression.predict.RegressionPredictorNodeModel();
        @SuppressWarnings("deprecation") PortObject[] regrPredOut = regrPredictor.execute(inData, exec);
        if (regrPredOut.length > 0 && regrPredOut[0] instanceof BufferedDataTable) {
            BufferedDataTable regrPredOutTable = (BufferedDataTable) regrPredOut[0];
            // replace name of prediction column (the last column of regrPredOutTable)
            return new PortObject[] { adjustSpecOfRegressionPredictorTable(regrPredOutTable, inData, exec) };
        } else {
            return regrPredOut;
        }
    }
    PMMLGeneralRegressionTranslator trans = new PMMLGeneralRegressionTranslator();
    port.initializeModelTranslator(trans);
    BufferedDataTable data = (BufferedDataTable) inData[1];
    DataTableSpec spec = data.getDataTableSpec();
    ColumnRearranger c = createRearranger(trans.getContent(), port.getSpec(), spec);
    BufferedDataTable out = exec.createColumnRearrangeTable(data, c, exec);
    return new BufferedDataTable[] { out };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLGeneralRegressionTranslator(org.knime.base.node.mine.regression.pmmlgreg.PMMLGeneralRegressionTranslator) Node(org.w3c.dom.Node) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

DataTableSpec (org.knime.core.data.DataTableSpec)938 DataColumnSpec (org.knime.core.data.DataColumnSpec)340 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)306 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)228 BufferedDataTable (org.knime.core.node.BufferedDataTable)226 DataCell (org.knime.core.data.DataCell)186 DataRow (org.knime.core.data.DataRow)170 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)136 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)129 DataType (org.knime.core.data.DataType)109 ArrayList (java.util.ArrayList)106 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)98 DoubleValue (org.knime.core.data.DoubleValue)94 DefaultRow (org.knime.core.data.def.DefaultRow)92 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)90 ExecutionContext (org.knime.core.node.ExecutionContext)68 PortObject (org.knime.core.node.port.PortObject)66 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)62 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)61 RowKey (org.knime.core.data.RowKey)59