use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class RandomForestClassificationLearnerNodeDialogPane method saveSettingsTo.
/**
* {@inheritDoc}
*/
@Override
protected void saveSettingsTo(final NodeSettingsWO settings) throws InvalidSettingsException {
TreeEnsembleLearnerConfiguration cfg = new TreeEnsembleLearnerConfiguration(false);
m_optionPanel.saveSettings(cfg);
cfg.save(settings);
}
use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class RandomForestClassificationLearnerNodeModel method loadValidatedSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadValidatedSettingsFrom(final NodeSettingsRO settings) throws InvalidSettingsException {
TreeEnsembleLearnerConfiguration config = new TreeEnsembleLearnerConfiguration(false);
config.loadInModel(settings);
m_configuration = config;
}
use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class TreeLearnerClassification method learnSingleTree.
/**
* {@inheritDoc}
*/
@Override
public TreeModelClassification learnSingleTree(final ExecutionMonitor exec, final RandomData rd) throws CanceledExecutionException {
final TreeData data = getData();
final RowSample rowSampling = getRowSampling();
final TreeEnsembleLearnerConfiguration config = getConfig();
final TreeTargetNominalColumnData targetColumn = (TreeTargetNominalColumnData) data.getTargetColumn();
double[] dataMemberships = new double[data.getNrRows()];
for (int i = 0; i < dataMemberships.length; i++) {
// dataMemberships[i] = m_rowSampling.getCountFor(i) > 0 ? 1.0 : 0.0;
dataMemberships[i] = rowSampling.getCountFor(i);
}
ClassificationPriors targetPriors = targetColumn.getDistribution(dataMemberships, config);
BitSet forbiddenColumnSet = new BitSet(data.getNrAttributes());
// TreeNodeMembershipController rootMembershipController = new TreeNodeMembershipController(data, dataMemberships);
TreeNodeMembershipController rootMembershipController = null;
TreeNodeClassification rootNode = buildTreeNode(exec, 0, dataMemberships, TreeNodeSignature.ROOT_SIGNATURE, targetPriors, forbiddenColumnSet, rootMembershipController);
assert forbiddenColumnSet.cardinality() == 0;
rootNode.setTreeNodeCondition(TreeNodeTrueCondition.INSTANCE);
return new TreeModelClassification(rootNode);
}
use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class TreeLearnerClassification method findBestSplitClassification.
private SplitCandidate findBestSplitClassification(final int currentDepth, final double[] rowSampleWeights, final TreeNodeSignature treeNodeSignature, final ClassificationPriors targetPriors, final BitSet forbiddenColumnSet, final TreeNodeMembershipController membershipController) {
final TreeData data = getData();
final ColumnSampleStrategy colSamplingStrategy = getColSamplingStrategy();
final TreeEnsembleLearnerConfiguration config = getConfig();
final int maxLevels = config.getMaxLevels();
if (maxLevels != TreeEnsembleLearnerConfiguration.MAX_LEVEL_INFINITE && currentDepth >= maxLevels) {
return null;
}
final int minNodeSize = config.getMinNodeSize();
if (minNodeSize != TreeEnsembleLearnerConfiguration.MIN_NODE_SIZE_UNDEFINED) {
if (targetPriors.getNrRecords() < minNodeSize) {
return null;
}
}
final double priorImpurity = targetPriors.getPriorImpurity();
if (priorImpurity < TreeColumnData.EPSILON) {
return null;
}
final TreeTargetNominalColumnData targetColumn = (TreeTargetNominalColumnData) data.getTargetColumn();
SplitCandidate splitCandidate = null;
if (currentDepth == 0 && config.getHardCodedRootColumn() != null) {
final TreeAttributeColumnData rootColumn = data.getColumn(config.getHardCodedRootColumn());
return rootColumn.calcBestSplitClassification(membershipController, rowSampleWeights, targetPriors, targetColumn);
} else {
double bestGainValue = 0.0;
final ColumnSample columnSample = colSamplingStrategy.getColumnSampleForTreeNode(treeNodeSignature);
for (TreeAttributeColumnData col : columnSample) {
if (forbiddenColumnSet.get(col.getMetaData().getAttributeIndex())) {
continue;
}
SplitCandidate currentColSplit = col.calcBestSplitClassification(membershipController, rowSampleWeights, targetPriors, targetColumn);
if (currentColSplit != null) {
double gainValue = currentColSplit.getGainValue();
if (gainValue > bestGainValue) {
bestGainValue = gainValue;
splitCandidate = currentColSplit;
}
}
}
}
return splitCandidate;
}
use of org.knime.base.node.mine.treeensemble.node.learner.TreeEnsembleLearnerConfiguration in project knime-core by knime.
the class TreeEnsembleClassificationLearnerNodeDialogPane method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
final DataTableSpec inSpec = specs[0];
TreeEnsembleLearnerConfiguration cfg = new TreeEnsembleLearnerConfiguration(false);
cfg.loadInDialog(settings, inSpec);
m_attributeSelectionPanel.loadSettingsFrom(inSpec, cfg);
m_treeOptionsPanel.loadSettingsFrom(inSpec, cfg);
m_ensembleOptionsPanel.loadSettings(cfg);
}
Aggregations