Search in sources :

Example 11 with PortObjectSpec

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

the class CategoryToNumberNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = (DataTableSpec) inSpecs[0];
    List<String> inputCols = new ArrayList<String>();
    for (DataColumnSpec column : inSpec) {
        if (column.getType().isCompatible(StringValue.class)) {
            inputCols.add(column.getName());
        }
    }
    // Auto configuration when included columns are not set
    if (null == m_settings.getIncludedColumns()) {
        // when there is no column with nominal data
        if (inputCols.isEmpty()) {
            throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
        } else {
            // auto-configure
            m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
        }
    } else {
        if (!m_settings.getIncludeAll()) {
            if (m_settings.getIncludedColumns().length == 0) {
                setWarningMessage("No columns selected.");
            }
            List<String> included = new ArrayList<String>();
            included.addAll(Arrays.asList(m_settings.getIncludedColumns()));
            included.removeAll(inputCols);
            if (!included.isEmpty()) {
                // output first missing column
                throw new InvalidSettingsException("Missing column: " + included.get(0).toString());
            }
        } else {
            if (inputCols.isEmpty()) {
                throw new InvalidSettingsException("No column in " + "the input compatible to \"StringValue\".");
            } else {
                // automatically add all columns
                m_settings.setIncludedColumns(inputCols.toArray(new String[inputCols.size()]));
            }
        }
    }
    ColumnRearranger rearranger = createRearranger(inSpec);
    PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[1];
    PMMLPortObjectSpecCreator pmmlSpecCreator = new PMMLPortObjectSpecCreator(pmmlSpec, inSpec);
    pmmlSpecCreator.addPreprocColNames(inputCols);
    return new PortObjectSpec[] { rearranger.createSpec(), pmmlSpecCreator.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PMMLPortObjectSpecCreator(org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)

Example 12 with PortObjectSpec

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

the class RandomForestClassificationLearnerNodeModel 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);
    // 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();
    final TreeEnsemblePredictor outOfBagPredictor = createOutOfBagPredictor(ensembleSpec, null, inSpec);
    ColumnRearranger outOfBagRearranger = outOfBagPredictor.getPredictionRearranger();
    DataTableSpec outOfBagSpec = outOfBagRearranger == null ? null : outOfBagRearranger.createSpec();
    DataTableSpec colStatsSpec = TreeEnsembleLearner.getColumnStatisticTableSpec();
    return new PortObjectSpec[] { outOfBagSpec, colStatsSpec, ensembleSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) FilterLearnColumnRearranger(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) 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) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) TreeEnsemblePredictor(org.knime.base.node.mine.treeensemble2.node.predictor.TreeEnsemblePredictor)

Example 13 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);
    }
    m_configuration.checkColumnSelection(inSpec);
    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.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.FilterLearnColumnRearranger) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) RegressionTreeModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.RegressionTreeModelPortObjectSpec)

Example 14 with PortObjectSpec

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

the class GradientBoostingRegressionLearnerNodeModel 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);
    // 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 15 with PortObjectSpec

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

the class GradientBoostingPMMLPredictorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    PMMLPortObjectSpec pmmlSpec = (PMMLPortObjectSpec) inSpecs[0];
    DataType targetType = extractTargetType(pmmlSpec);
    if (m_isRegression && !targetType.isCompatible(DoubleValue.class)) {
        throw new InvalidSettingsException("This node expects a regression model.");
    } else if (!m_isRegression && !targetType.isCompatible(StringValue.class)) {
        throw new InvalidSettingsException("This node expectes a classification model.");
    }
    try {
        AbstractTreeModelPMMLTranslator.checkPMMLSpec(pmmlSpec);
    } catch (IllegalArgumentException e) {
        throw new InvalidSettingsException(e.getMessage());
    }
    TreeEnsembleModelPortObjectSpec modelSpec = translateSpec(pmmlSpec);
    String targetColName = modelSpec.getTargetColumn().getName();
    if (m_configuration == null) {
        m_configuration = TreeEnsemblePredictorConfiguration.createDefault(m_isRegression, targetColName);
    } else if (!m_configuration.isChangePredictionColumnName()) {
        m_configuration.setPredictionColumnName(TreeEnsemblePredictorConfiguration.getPredictColumnName(targetColName));
    }
    modelSpec.assertTargetTypeMatches(m_isRegression);
    DataTableSpec dataSpec = (DataTableSpec) inSpecs[1];
    final GradientBoostingPredictor<GradientBoostedTreesModel> pred = new GradientBoostingPredictor<>(null, modelSpec, dataSpec, m_configuration);
    return new PortObjectSpec[] { pred.getPredictionRearranger().createSpec() };
}
Also used : PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) GradientBoostingPredictor(org.knime.base.node.mine.treeensemble2.node.gradientboosting.predictor.GradientBoostingPredictor) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) TreeEnsembleModelPortObjectSpec(org.knime.base.node.mine.treeensemble2.model.TreeEnsembleModelPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) DataType(org.knime.core.data.DataType) GradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.GradientBoostedTreesModel) MultiClassGradientBoostedTreesModel(org.knime.base.node.mine.treeensemble2.model.MultiClassGradientBoostedTreesModel) StringValue(org.knime.core.data.StringValue)

Aggregations

PortObjectSpec (org.knime.core.node.port.PortObjectSpec)123 DataTableSpec (org.knime.core.data.DataTableSpec)91 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)81 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)35 DataColumnSpec (org.knime.core.data.DataColumnSpec)28 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)28 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)24 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)19 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)18 IOException (java.io.IOException)17 PortObject (org.knime.core.node.port.PortObject)14 PMMLPortObjectSpecCreator (org.knime.core.node.port.pmml.PMMLPortObjectSpecCreator)14 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)12 DatabaseQueryConnectionSettings (org.knime.core.node.port.database.DatabaseQueryConnectionSettings)12 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)12 DataType (org.knime.core.data.DataType)11 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 DoubleValue (org.knime.core.data.DoubleValue)10