Search in sources :

Example 1 with MissingValueHandling

use of org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.MissingValueHandling in project knime-core by knime.

the class AdvancedOptionsPanel method saveSettings.

public void saveSettings(final GradientBoostingLearnerConfiguration cfg) throws InvalidSettingsException {
    cfg.setAlpha((Double) m_alphaFractionSpinner.getValue());
    cfg.setUseAverageSplitPoints(m_useAverageSplitPointsChecker.isSelected());
    cfg.setUseBinaryNominalSplits(m_useBinaryNominalSplitsChecker.isSelected());
    final MissingValueHandling missValHandling = (MissingValueHandling) m_missingValueHandlingComboBox.getSelectedItem();
    if (missValHandling == MissingValueHandling.Surrogate && !m_useBinaryNominalSplitsChecker.isSelected()) {
        throw new InvalidSettingsException("Surrogate missing value handling can only be used if binary nominal splits are enabled.");
    }
    cfg.setMissingValueHandling((MissingValueHandling) m_missingValueHandlingComboBox.getSelectedItem());
    double dataFrac;
    boolean isSamplingWithReplacement;
    if (m_dataFractionPerTreeChecker.isSelected()) {
        dataFrac = (Double) m_dataFractionPerTreeSpinner.getValue();
        isSamplingWithReplacement = m_dataSamplingWithReplacementChecker.isSelected();
    } else {
        dataFrac = 1.0;
        isSamplingWithReplacement = false;
    }
    cfg.setDataFractionPerTree(dataFrac);
    cfg.setDataSelectionWithReplacement(isSamplingWithReplacement);
    ColumnSamplingMode cf;
    double columnFrac = 1.0;
    int columnAbsolute = TreeEnsembleLearnerConfiguration.DEF_COLUMN_ABSOLUTE;
    boolean isUseDifferentAttributesAtEachNode = m_columnUseDifferentSetOfAttributesForNodes.isSelected();
    if (m_columnFractionNoneButton.isSelected()) {
        cf = ColumnSamplingMode.None;
        isUseDifferentAttributesAtEachNode = false;
    } else if (m_columnFractionLinearButton.isSelected()) {
        cf = ColumnSamplingMode.Linear;
        columnFrac = (Double) m_columnFractionLinearTreeSpinner.getValue();
    } else if (m_columnFractionAbsoluteButton.isSelected()) {
        cf = ColumnSamplingMode.Absolute;
        columnAbsolute = (Integer) m_columnFractionAbsoluteTreeSpinner.getValue();
    } else if (m_columnFractionSqrtButton.isSelected()) {
        cf = ColumnSamplingMode.SquareRoot;
    } else {
        throw new InvalidSettingsException("No column selection policy selected");
    }
    cfg.setColumnSamplingMode(cf);
    cfg.setColumnFractionLinearValue(columnFrac);
    cfg.setColumnAbsoluteValue(columnAbsolute);
    cfg.setUseDifferentAttributesAtEachNode(isUseDifferentAttributesAtEachNode);
    Long seed;
    if (m_seedChecker.isSelected()) {
        final String seedText = m_seedTextField.getText();
        try {
            seed = Long.valueOf(seedText);
        } catch (Exception e) {
            throw new InvalidSettingsException("Unable to parse seed \"" + seedText + "\"", e);
        }
    } else {
        seed = null;
    }
    cfg.setSeed(seed);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) MissingValueHandling(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.MissingValueHandling) ColumnSamplingMode(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.ColumnSamplingMode) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 2 with MissingValueHandling

use of org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.MissingValueHandling in project knime-core by knime.

the class OptionsPanel method saveSettings.

/**
 * Save settings in config <b>cfg</b>
 *
 * @param cfg
 * @throws InvalidSettingsException
 */
public void saveSettings(final TreeEnsembleLearnerConfiguration cfg) throws InvalidSettingsException {
    cfg.setTargetColumn(m_targetColumnBox.getSelectedColumn());
    if (m_useFingerprintColumnRadio.isSelected()) {
        String fpColumn = m_fingerprintColumnBox.getSelectedColumn();
        cfg.setFingerprintColumn(fpColumn);
    // cfg.setIncludeAllColumns(false);
    } else {
        assert m_useOrdinaryColumnsRadio.isSelected();
        // boolean useAll = m_includeColumnsFilterPanel.isKeepAllSelected();
        // if (useAll) {
        // cfg.setIncludeAllColumns(true);
        // } else {
        // cfg.setIncludeAllColumns(false);
        // Set<String> incls = m_includeColumnsFilterPanel.getIncludedColumnSet();
        Set<String> incls = m_includeColumnsFilterPanel2.getIncludedNamesAsSet();
        if (incls.size() == 0) {
            throw new InvalidSettingsException("No learn columns selected");
        }
    // }
    }
    m_includeColumnsFilterPanel2.saveConfiguration(cfg.getColumnFilterConfig());
    int hiliteCount = m_enableHiliteChecker.isSelected() ? (Integer) m_hiliteCountSpinner.getValue() : -1;
    cfg.setNrHilitePatterns(hiliteCount);
    cfg.setIgnoreColumnsWithoutDomain(m_ignoreColumnsWithoutDomainChecker.isSelected());
    // cfg.setSaveTargetDistributionInNodes(false);
    // cfg.setIgnoreColumnsWithoutDomain(m_ignoreColumnsWithoutDomainChecker.isSelected());
    // cfg.setSaveTargetDistributionInNodes(m_saveTargetDistributionInNodesChecker.isSelected());
    // Tree Options
    cfg.setSplitCriterion(SplitCriterion.Gini);
    // cfg.setUseAverageSplitPoints(m_useAverageSplitPointsChecker.isSelected());
    cfg.setUseBinaryNominalSplits(m_useBinaryNominalSplitsCheckBox.isSelected());
    final MissingValueHandling missValHandling = (MissingValueHandling) m_missingValueHandlingComboBox.getSelectedItem();
    if (missValHandling == MissingValueHandling.Surrogate && !m_useBinaryNominalSplitsCheckBox.isSelected()) {
        throw new InvalidSettingsException("Surrogate missing value handling only works if binary nominal splits are enabled");
    }
    cfg.setMissingValueHandling(missValHandling);
    cfg.setUseAverageSplitPoints(true);
    int maxLevel = m_maxLevelChecker.isSelected() ? (Integer) m_maxLevelSpinner.getValue() : TreeEnsembleLearnerConfiguration.MAX_LEVEL_INFINITE;
    cfg.setMaxLevels(maxLevel);
    int minNodeSize = m_minNodeSizeChecker.isSelected() ? (Integer) m_minNodeSizeSpinner.getValue() : TreeEnsembleLearnerConfiguration.MIN_NODE_SIZE_UNDEFINED;
    int minChildNodeSize = m_minChildNodeSizeChecker.isSelected() ? (Integer) m_minChildNodeSizeSpinner.getValue() : TreeEnsembleLearnerConfiguration.MIN_CHILD_SIZE_UNDEFINED;
    cfg.setMinSizes(minNodeSize, minChildNodeSize);
    cfg.setHardCodedRootColumn(null);
    // Forest Options
    ColumnSamplingMode cf = ColumnSamplingMode.None;
    double columnFrac = 1.0;
    int columnAbsolute = TreeEnsembleLearnerConfiguration.DEF_COLUMN_ABSOLUTE;
    cfg.setColumnSamplingMode(cf);
    cfg.setColumnFractionLinearValue(columnFrac);
    cfg.setColumnAbsoluteValue(columnAbsolute);
    cfg.setUseDifferentAttributesAtEachNode(false);
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) MissingValueHandling(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.MissingValueHandling) ColumnSamplingMode(org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.ColumnSamplingMode)

Aggregations

ColumnSamplingMode (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.ColumnSamplingMode)2 MissingValueHandling (org.knime.base.node.mine.treeensemble2.node.learner.TreeEnsembleLearnerConfiguration.MissingValueHandling)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2