Search in sources :

Example 26 with DecisionTree

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

the class DecTreePredictorGraphView method modelChanged.

/**
 * {@inheritDoc}
 */
@Override
protected void modelChanged() {
    DecTreePredictorNodeModel model = this.getNodeModel();
    if (model != null) {
        m_hiLiteHdl.removeHiLiteListener(this);
        DecisionTree dt = model.getDecisionTree();
        if (dt != null) {
            m_graph.setColorColumn(model.getDecisionTree().getColorColumn());
            m_graph.setRootNode(dt.getRootNode());
            // retrieve HiLiteHandler from Input port
            m_hiLiteHdl = model.getInHiLiteHandler(DecTreePredictorNodeModel.INDATAPORT);
            // and adjust menu entries for HiLite-ing
            m_hiLiteMenu.setEnabled(m_hiLiteHdl != null);
            m_hiLiteHdl.addHiLiteListener(this);
            recreateHiLite();
        } else {
            m_graph.setColorColumn(null);
            m_graph.setRootNode(null);
        }
    }
}
Also used : DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree)

Example 27 with DecisionTree

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

the class DecTreePredictorNodeModel method loadInternals.

/**
 * Load internals.
 *
 * @param nodeInternDir The intern node directory to load tree from.
 * @param exec Used to report progress or cancel saving.
 * @throws IOException Always, since this method has not been implemented
 *             yet.
 * @see org.knime.core.node.NodeModel
 *      #loadInternals(java.io.File,ExecutionMonitor)
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    // read the decision tree
    File internalsFile = new File(nodeInternDir, INTERNALS_FILE_NAME);
    if (!internalsFile.exists()) {
        // file to load internals from not available
        setWarningMessage("Internal model could not be loaded.");
        return;
    }
    BufferedInputStream in2 = new BufferedInputStream(new GZIPInputStream(new FileInputStream(internalsFile)));
    ModelContentRO binModel = ModelContent.loadFromXML(in2);
    try {
        m_decTree = new DecisionTree(binModel);
    } catch (InvalidSettingsException ise) {
        LOGGER.warn("Model (internals) could not be loaded.", ise);
        setWarningMessage("Internal model could not be loaded.");
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) ModelContentRO(org.knime.core.node.ModelContentRO) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 28 with DecisionTree

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

the class TreeEnsembleModel method createDecisionTree.

public DecisionTree createDecisionTree(final int modelIndex, final DataTable sampleForHiliting) {
    final DecisionTree result;
    final TreeMetaData metaData = getMetaData();
    if (metaData.isRegression()) {
        TreeModelRegression treeModel = getTreeModelRegression(modelIndex);
        result = treeModel.createDecisionTree(metaData);
    } else {
        TreeModelClassification treeModel = getTreeModelClassification(modelIndex);
        result = treeModel.createDecisionTree(metaData);
    }
    if (sampleForHiliting != null) {
        final DataTableSpec dataSpec = sampleForHiliting.getDataTableSpec();
        final DataTableSpec spec = getLearnAttributeSpec(dataSpec);
        for (DataRow r : sampleForHiliting) {
            try {
                DataRow fullAttributeRow = createLearnAttributeRow(r, spec);
                result.addCoveredPattern(fullAttributeRow, spec);
            } catch (Exception e) {
                // dunno what to do with that
                NodeLogger.getLogger(getClass()).error("Error updating hilite info in tree view", e);
                break;
            }
        }
    }
    return result;
}
Also used : DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) DataTableSpec(org.knime.core.data.DataTableSpec) TreeMetaData(org.knime.base.node.mine.treeensemble2.data.TreeMetaData) DataRow(org.knime.core.data.DataRow) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 29 with DecisionTree

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

the class DecTreePredictorGraphView method modelChanged.

/**
 * {@inheritDoc}
 */
@Override
protected void modelChanged() {
    DecTreePredictorNodeModel model = this.getNodeModel();
    if (model != null) {
        m_hiLiteHdl.removeHiLiteListener(this);
        DecisionTree dt = model.getDecisionTree();
        if (dt != null) {
            m_graph.setColorColumn(model.getDecisionTree().getColorColumn());
            m_graph.setRootNode(dt.getRootNode());
            // retrieve HiLiteHandler from Input port
            m_hiLiteHdl = model.getInHiLiteHandler(DecTreePredictorNodeModel.INDATAPORT);
            // and adjust menu entries for HiLite-ing
            m_hiLiteMenu.setEnabled(m_hiLiteHdl != null);
            m_hiLiteHdl.addHiLiteListener(this);
            recreateHiLite();
        } else {
            m_graph.setColorColumn(null);
            m_graph.setRootNode(null);
        }
    }
}
Also used : DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree)

Example 30 with DecisionTree

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

the class DecTreePredictorNodeModel method loadInternals.

/**
 * Load internals.
 *
 * @param nodeInternDir The intern node directory to load tree from.
 * @param exec Used to report progress or cancel saving.
 * @throws IOException Always, since this method has not been implemented
 *             yet.
 * @see org.knime.core.node.NodeModel
 *      #loadInternals(java.io.File,ExecutionMonitor)
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    // read the decision tree
    File internalsFile = new File(nodeInternDir, INTERNALS_FILE_NAME);
    if (!internalsFile.exists()) {
        // file to load internals from not available
        setWarningMessage("Internal model could not be loaded.");
        return;
    }
    BufferedInputStream in2 = new BufferedInputStream(new GZIPInputStream(new FileInputStream(internalsFile)));
    ModelContentRO binModel = ModelContent.loadFromXML(in2);
    try {
        m_decTree = new DecisionTree(binModel);
    } catch (InvalidSettingsException ise) {
        LOGGER.warn("Model (internals) could not be loaded.", ise);
        setWarningMessage("Internal model could not be loaded.");
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) ModelContentRO(org.knime.core.node.ModelContentRO) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

DecisionTree (org.knime.base.node.mine.decisiontree2.model.DecisionTree)24 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)11 IOException (java.io.IOException)9 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)9 DataTableSpec (org.knime.core.data.DataTableSpec)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 DataRow (org.knime.core.data.DataRow)6 BufferedInputStream (java.io.BufferedInputStream)5 File (java.io.File)5 FileInputStream (java.io.FileInputStream)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 PMMLDecisionTreeTranslator (org.knime.base.node.mine.decisiontree2.PMMLDecisionTreeTranslator)5 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)5 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)4 DecisionTreeNodeRenderer (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeRenderer)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 ModelContentRO (org.knime.core.node.ModelContentRO)4 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)4 DecisionTreeNodeLeaf (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf)3