Search in sources :

Example 1 with AbstractTreeNode

use of org.knime.base.node.mine.treeensemble.model.AbstractTreeNode in project knime-core by knime.

the class TreeEnsembleLearner method createColumnStatisticTable.

public BufferedDataTable createColumnStatisticTable(final ExecutionContext exec) throws CanceledExecutionException {
    BufferedDataContainer c = exec.createDataContainer(getColumnStatisticTableSpec());
    final int nrModels = m_ensembleModel.getNrModels();
    final TreeAttributeColumnData[] columns = m_data.getColumns();
    final int nrAttributes = columns.length;
    int[][] columnOnLevelCounts = new int[REPORT_LEVEL][nrAttributes];
    int[][] columnInLevelSampleCounts = new int[REPORT_LEVEL][nrAttributes];
    for (int i = 0; i < nrModels; i++) {
        final AbstractTreeModel<?> treeModel = m_ensembleModel.getTreeModel(i);
        for (int level = 0; level < REPORT_LEVEL; level++) {
            for (AbstractTreeNode treeNodeOnLevel : treeModel.getTreeNodes(level)) {
                TreeNodeSignature sig = treeNodeOnLevel.getSignature();
                ColumnSampleStrategy colStrat = m_columnSampleStrategies[i];
                ColumnSample cs = colStrat.getColumnSampleForTreeNode(sig);
                for (TreeAttributeColumnData col : cs) {
                    final int index = col.getMetaData().getAttributeIndex();
                    columnInLevelSampleCounts[level][index] += 1;
                }
                int splitAttIdx = treeNodeOnLevel.getSplitAttributeIndex();
                if (splitAttIdx >= 0) {
                    columnOnLevelCounts[level][splitAttIdx] += 1;
                }
            }
        }
    }
    for (int i = 0; i < nrAttributes; i++) {
        String name = columns[i].getMetaData().getAttributeName();
        int[] counts = new int[2 * REPORT_LEVEL];
        for (int level = 0; level < REPORT_LEVEL; level++) {
            counts[level] = columnOnLevelCounts[level][i];
            counts[REPORT_LEVEL + level] = columnInLevelSampleCounts[level][i];
        }
        DataRow row = new DefaultRow(name, counts);
        c.addRowToTable(row);
        exec.checkCanceled();
    }
    c.close();
    return c.getTable();
}
Also used : ColumnSampleStrategy(org.knime.base.node.mine.treeensemble.sample.column.ColumnSampleStrategy) TreeAttributeColumnData(org.knime.base.node.mine.treeensemble.data.TreeAttributeColumnData) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ColumnSample(org.knime.base.node.mine.treeensemble.sample.column.ColumnSample) AbstractTreeNode(org.knime.base.node.mine.treeensemble.model.AbstractTreeNode) TreeNodeSignature(org.knime.base.node.mine.treeensemble.model.TreeNodeSignature) DataRow(org.knime.core.data.DataRow) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

TreeAttributeColumnData (org.knime.base.node.mine.treeensemble.data.TreeAttributeColumnData)1 AbstractTreeNode (org.knime.base.node.mine.treeensemble.model.AbstractTreeNode)1 TreeNodeSignature (org.knime.base.node.mine.treeensemble.model.TreeNodeSignature)1 ColumnSample (org.knime.base.node.mine.treeensemble.sample.column.ColumnSample)1 ColumnSampleStrategy (org.knime.base.node.mine.treeensemble.sample.column.ColumnSampleStrategy)1 DataRow (org.knime.core.data.DataRow)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1