Search in sources :

Example 66 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class RegressionTreeLearnerNodeModel 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);
    }
    DataTableSpec learnSpec = learnRearranger.createSpec();
    RegressionTreeModelPortObjectSpec treeSpec = new RegressionTreeModelPortObjectSpec(learnSpec);
    return new PortObjectSpec[] { treeSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.RegressionTreeModelPortObjectSpec)

Example 67 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class TreeEnsembleShrinkerNodeModel method configure.

@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    TreeEnsembleModelPortObjectSpec modelSpec = (TreeEnsembleModelPortObjectSpec) inSpecs[0];
    modelSpec.assertTargetTypeMatches(false);
    DataTableSpec tableSpec = (DataTableSpec) inSpecs[1];
    int targetColumnIndex = tableSpec.findColumnIndex(m_config.getTargetColumn());
    if (targetColumnIndex < 0 || !tableSpec.getColumnSpec(targetColumnIndex).getType().isCompatible(StringValue.class)) {
        throw new InvalidSettingsException("No valid target column selected");
    }
    return new PortObjectSpec[] { null };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObjectSpec)

Example 68 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class GradientBoostingClassificationLearnerNodeModel 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);
    ensembleSpec.assertTargetTypeMatches(false);
    // 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();
    return new PortObjectSpec[] { ensembleSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec)

Example 69 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class NaiveBayesPredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    // check the input data
    assert (inSpecs != null && inSpecs.length == 2 && inSpecs[DATA_IN_PORT] != null && inSpecs[MODEL_IN_PORT] != null);
    final PortObjectSpec modelObject = inSpecs[MODEL_IN_PORT];
    if (!(modelObject instanceof NaiveBayesPortObjectSpec)) {
        throw new IllegalArgumentException("Invalid input data");
    }
    final DataTableSpec trainingSpec = ((NaiveBayesPortObjectSpec) modelObject).getTableSpec();
    final DataColumnSpec classColumn = ((NaiveBayesPortObjectSpec) modelObject).getClassColumn();
    if (trainingSpec == null) {
        throw new InvalidSettingsException("No model spec available");
    }
    final PortObjectSpec inSpec = inSpecs[DATA_IN_PORT];
    if (!(inSpec instanceof DataTableSpec)) {
        throw new IllegalArgumentException("TableSpec must not be null");
    }
    final DataTableSpec spec = (DataTableSpec) inSpec;
    // check the input data for columns with the wrong name or wrong type
    final List<String> unknownCols = check4UnknownCols(trainingSpec, spec);
    if (unknownCols.size() >= spec.getNumColumns()) {
        setWarningMessage("No known attribute columns found use " + "class prior probability to predict the class membership");
    } else if (unknownCols.size() == 1) {
        setWarningMessage("Input column " + unknownCols.get(0) + " is unknown and will be skipped.");
    } else if (unknownCols.size() > 1) {
        final StringBuilder buf = new StringBuilder();
        buf.append("The following input columns are unknown and " + "will be skipped: ");
        for (int i = 0, length = unknownCols.size(); i < length; i++) {
            if (i != 0) {
                buf.append(", ");
            }
            if (i > 3) {
                buf.append("...");
                break;
            }
            buf.append(unknownCols.get(i));
        }
        setWarningMessage(buf.toString());
    }
    // check if the learned model contains columns which are not in the
    // input data
    final List<String> missingInputCols = check4MissingCols(trainingSpec, classColumn.getName(), spec);
    if (missingInputCols.size() == 1) {
        setWarningMessage("Attribute " + missingInputCols.get(0) + " is missing in the input data");
    } else if (missingInputCols.size() > 1) {
        final StringBuilder buf = new StringBuilder();
        buf.append("The following attributes are missing in " + "the input data: ");
        for (int i = 0, length = missingInputCols.size(); i < length; i++) {
            if (i != 0) {
                buf.append(", ");
            }
            if (i > 3) {
                buf.append("...");
                break;
            }
            buf.append(missingInputCols.get(i));
        }
        setWarningMessage(buf.toString());
    }
    final PredictorHelper predictorHelper = PredictorHelper.getInstance();
    final DataColumnSpec resultColSpecs = NaiveBayesCellFactory.createResultColSpecs(predictorHelper.computePredictionColumnName(m_predictionColumnName.getStringValue(), m_overridePredicted.getBooleanValue(), classColumn.getName()), classColumn.getType(), spec, m_inclProbVals.getBooleanValue());
    if (resultColSpecs != null) {
        return new PortObjectSpec[] { AppendedColumnTable.getTableSpec(spec, resultColSpecs) };
    }
    return null;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) PredictorHelper(org.knime.base.node.mine.util.PredictorHelper) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NaiveBayesPortObjectSpec(org.knime.base.node.mine.bayes.naivebayes.port.NaiveBayesPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) NaiveBayesPortObjectSpec(org.knime.base.node.mine.bayes.naivebayes.port.NaiveBayesPortObjectSpec) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 70 with PortObjectSpec

use of org.knime.core.node.port.PortObjectSpec in project knime-core by knime.

the class DecTreePredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMMLPortObjectSpec treeSpec = (PMMLPortObjectSpec) inSpecs[INMODELPORT];
    DataTableSpec inSpec = (DataTableSpec) inSpecs[1];
    for (String learnColName : treeSpec.getLearningFields()) {
        if (!inSpec.containsName(learnColName)) {
            throw new InvalidSettingsException("Learning column \"" + learnColName + "\" not found in input " + "data to be predicted");
        }
    }
    return new PortObjectSpec[] { createOutTableSpec(inSpecs) };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec)

Aggregations

PortObjectSpec (org.knime.core.node.port.PortObjectSpec)139 DataTableSpec (org.knime.core.data.DataTableSpec)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)86 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)35 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)30 DataColumnSpec (org.knime.core.data.DataColumnSpec)29 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)25 IOException (java.io.IOException)24 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)24 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)24 PortObject (org.knime.core.node.port.PortObject)19 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)16 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)16 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)14 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)12 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)12 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)12