Search in sources :

Example 46 with DecisionTreeNode

use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.

the class TreeEnsembleLearnerNodeView method recreateHiLite.

private void recreateHiLite() {
    HiLiteHandler handler = m_hiLiteHdl;
    if (handler == null) {
        return;
    }
    Set<RowKey> hilited = handler.getHiLitKeys();
    Set<DecisionTreeNode> toHilite = new HashSet<DecisionTreeNode>();
    DecisionTreeNode root = m_graph.getRootNode();
    List<DecisionTreeNode> toProcess = new LinkedList<DecisionTreeNode>();
    if (null != root) {
        toProcess.add(0, root);
    }
    // Traverse the tree breadth first
    while (!toProcess.isEmpty()) {
        DecisionTreeNode curr = toProcess.remove(0);
        // cover any pattern
        if (curr.coveredPattern().isEmpty()) {
            continue;
        }
        if (hilited.containsAll(curr.coveredPattern())) {
            // hilite subtree starting from curr
            toHilite.addAll(getSubtree(curr));
        } else {
            for (int i = 0; i < curr.getChildCount(); i++) {
                toProcess.add(0, curr.getChildAt(i));
            }
        }
    }
    m_graph.hiLite(toHilite);
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) RowKey(org.knime.core.data.RowKey) LinkedList(java.util.LinkedList) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode) HashSet(java.util.HashSet)

Example 47 with DecisionTreeNode

use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.

the class TreeNodeClassification method createDecisionTreeNode.

/**
 * Creates DecisionTreeNode model that is used in Decision Tree of KNIME
 *
 * @param idGenerator
 * @param metaData
 * @return a DecisionTreeNode
 */
public DecisionTreeNode createDecisionTreeNode(final MutableInteger idGenerator, final TreeMetaData metaData) {
    DataCell majorityCell = new StringCell(getMajorityClassName());
    final float[] targetDistribution = getTargetDistribution();
    int initSize = (int) (targetDistribution.length / 0.75 + 1.0);
    LinkedHashMap<DataCell, Double> scoreDistributionMap = new LinkedHashMap<DataCell, Double>(initSize);
    NominalValueRepresentation[] targets = getTargetMetaData().getValues();
    for (int i = 0; i < targetDistribution.length; i++) {
        String cl = targets[i].getNominalValue();
        double d = targetDistribution[i];
        scoreDistributionMap.put(new StringCell(cl), d);
    }
    final int nrChildren = getNrChildren();
    if (nrChildren == 0) {
        return new DecisionTreeNodeLeaf(idGenerator.inc(), majorityCell, scoreDistributionMap);
    } else {
        int id = idGenerator.inc();
        DecisionTreeNode[] childNodes = new DecisionTreeNode[nrChildren];
        int splitAttributeIndex = getSplitAttributeIndex();
        assert splitAttributeIndex >= 0 : "non-leaf node has no split";
        String splitAttribute = metaData.getAttributeMetaData(splitAttributeIndex).getAttributeName();
        PMMLPredicate[] childPredicates = new PMMLPredicate[nrChildren];
        for (int i = 0; i < nrChildren; i++) {
            final TreeNodeClassification treeNode = getChild(i);
            TreeNodeCondition cond = treeNode.getCondition();
            childPredicates[i] = cond.toPMMLPredicate();
            childNodes[i] = treeNode.createDecisionTreeNode(idGenerator, metaData);
        }
        return new DecisionTreeNodeSplitPMML(id, majorityCell, scoreDistributionMap, splitAttribute, childPredicates, childNodes);
    }
}
Also used : NominalValueRepresentation(org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation) PMMLPredicate(org.knime.base.node.mine.decisiontree2.PMMLPredicate) LinkedHashMap(java.util.LinkedHashMap) DecisionTreeNodeLeaf(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf) StringCell(org.knime.core.data.def.StringCell) DecisionTreeNodeSplitPMML(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML) DataCell(org.knime.core.data.DataCell) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)

Example 48 with DecisionTreeNode

use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.

the class DecTreePredictorGraphView method createTreeMenu.

/**
 * Create menu to control tree.
 *
 * @return A new JMenu with tree operation buttons
 */
private JMenu createTreeMenu() {
    final JMenu result = new JMenu("Tree");
    result.setMnemonic('T');
    Action expand = new ExpandBranchAction<DecisionTreeNode>(m_graph);
    expand.putValue(Action.NAME, "Expand Selected Branch");
    Action collapse = new CollapseBranchAction<DecisionTreeNode>(m_graph);
    collapse.putValue(Action.NAME, "Collapse Selected Branch");
    result.add(expand);
    result.add(collapse);
    return result;
}
Also used : ExpandBranchAction(org.knime.base.node.mine.decisiontree2.view.graph.ExpandBranchAction) Action(javax.swing.Action) ExpandBranchAction(org.knime.base.node.mine.decisiontree2.view.graph.ExpandBranchAction) CollapseBranchAction(org.knime.base.node.mine.decisiontree2.view.graph.CollapseBranchAction) CollapseBranchAction(org.knime.base.node.mine.decisiontree2.view.graph.CollapseBranchAction) JMenu(javax.swing.JMenu)

Example 49 with DecisionTreeNode

use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.

the class DecTreePredictorGraphView method updateHiLite.

private void updateHiLite(final boolean state) {
    DecisionTreeNode selected = m_graph.getSelected();
    Set<RowKey> covPat = new HashSet<RowKey>();
    covPat.addAll(selected.coveredPattern());
    if (state) {
        m_hiLiteHdl.fireHiLiteEvent(covPat);
    } else {
        m_hiLiteHdl.fireUnHiLiteEvent(covPat);
    }
}
Also used : RowKey(org.knime.core.data.RowKey) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode) HashSet(java.util.HashSet)

Example 50 with DecisionTreeNode

use of org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode in project knime-core by knime.

the class DecTreePredictorGraphView method recreateHiLite.

private void recreateHiLite() {
    Set<RowKey> hilited = m_hiLiteHdl.getHiLitKeys();
    Set<DecisionTreeNode> toHilite = new HashSet<DecisionTreeNode>();
    DecisionTreeNode root = m_graph.getRootNode();
    List<DecisionTreeNode> toProcess = new LinkedList<DecisionTreeNode>();
    if (null != root) {
        toProcess.add(0, root);
    }
    // Traverse the tree breadth first
    while (!toProcess.isEmpty()) {
        DecisionTreeNode curr = toProcess.remove(0);
        if (hilited.containsAll(curr.coveredPattern())) {
            // hilite subtree starting from curr
            toHilite.addAll(getSubtree(curr));
        } else {
            for (int i = 0; i < curr.getChildCount(); i++) {
                toProcess.add(0, curr.getChildAt(i));
            }
        }
    }
    m_graph.hiLite(toHilite);
}
Also used : RowKey(org.knime.core.data.RowKey) LinkedList(java.util.LinkedList) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode) HashSet(java.util.HashSet)

Aggregations

DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)50 RowKey (org.knime.core.data.RowKey)18 HashSet (java.util.HashSet)14 LinkedList (java.util.LinkedList)14 DecisionTreeNodeLeaf (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf)12 ArrayList (java.util.ArrayList)10 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)10 DataCell (org.knime.core.data.DataCell)9 Action (javax.swing.Action)8 JMenu (javax.swing.JMenu)8 CollapseBranchAction (org.knime.base.node.mine.decisiontree2.view.graph.CollapseBranchAction)8 ExpandBranchAction (org.knime.base.node.mine.decisiontree2.view.graph.ExpandBranchAction)8 PMMLPredicate (org.knime.base.node.mine.decisiontree2.PMMLPredicate)7 PMMLDecisionTreeTranslator (org.knime.base.node.mine.decisiontree2.PMMLDecisionTreeTranslator)5 DecisionTree (org.knime.base.node.mine.decisiontree2.model.DecisionTree)5 TreePath (javax.swing.tree.TreePath)4 PortObject (org.knime.core.node.port.PortObject)4 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)4 LinkedHashMap (java.util.LinkedHashMap)3 PMMLSimplePredicate (org.knime.base.node.mine.decisiontree2.PMMLSimplePredicate)3