Search in sources :

Example 1 with TreeNodeTrueCondition

use of org.knime.base.node.mine.treeensemble2.model.TreeNodeTrueCondition in project knime-core by knime.

the class TreeModelPMMLTranslator method addTreeNode.

/**
 * @param pmmlNode
 * @param node
 */
private void addTreeNode(final Node pmmlNode, final AbstractTreeNode node) {
    int index = m_nodeIndex++;
    pmmlNode.setId(Integer.toString(index));
    if (node instanceof TreeNodeClassification) {
        final TreeNodeClassification clazNode = (TreeNodeClassification) node;
        pmmlNode.setScore(clazNode.getMajorityClassName());
        float[] targetDistribution = clazNode.getTargetDistribution();
        NominalValueRepresentation[] targetVals = clazNode.getTargetMetaData().getValues();
        double sum = 0.0;
        for (Float v : targetDistribution) {
            sum += v;
        }
        pmmlNode.setRecordCount(sum);
        // adding score distribution (class counts)
        for (int i = 0; i < targetDistribution.length; i++) {
            String className = targetVals[i].getNominalValue();
            double freq = targetDistribution[i];
            ScoreDistribution pmmlScoreDist = pmmlNode.addNewScoreDistribution();
            pmmlScoreDist.setValue(className);
            pmmlScoreDist.setRecordCount(freq);
        }
    } else if (node instanceof TreeNodeRegression) {
        final TreeNodeRegression regNode = (TreeNodeRegression) node;
        pmmlNode.setScore(Double.toString(regNode.getMean()));
    }
    TreeNodeCondition condition = node.getCondition();
    if (condition instanceof TreeNodeTrueCondition) {
        pmmlNode.addNewTrue();
    } else if (condition instanceof TreeNodeColumnCondition) {
        final TreeNodeColumnCondition colCondition = (TreeNodeColumnCondition) condition;
        handleColumnCondition(colCondition, pmmlNode);
    } else if (condition instanceof AbstractTreeNodeSurrogateCondition) {
        final AbstractTreeNodeSurrogateCondition surrogateCond = (AbstractTreeNodeSurrogateCondition) condition;
        setValuesFromPMMLCompoundPredicate(pmmlNode.addNewCompoundPredicate(), surrogateCond.toPMMLPredicate());
    } else {
        throw new IllegalStateException("Unsupported condition (not " + "implemented): " + condition.getClass().getSimpleName());
    }
    for (int i = 0; i < node.getNrChildren(); i++) {
        addTreeNode(pmmlNode.addNewNode(), node.getChild(i));
    }
}
Also used : NominalValueRepresentation(org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation) ScoreDistribution(org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution)

Example 2 with TreeNodeTrueCondition

use of org.knime.base.node.mine.treeensemble2.model.TreeNodeTrueCondition in project knime-core by knime.

the class ConditionExporter method exportCondition.

void exportCondition(final TreeNodeCondition condition, final Node pmmlNode) {
    if (condition instanceof TreeNodeTrueCondition) {
        pmmlNode.addNewTrue();
    } else if (condition instanceof TreeNodeColumnCondition) {
        final TreeNodeColumnCondition colCondition = (TreeNodeColumnCondition) condition;
        exportColumnCondition(colCondition, pmmlNode);
    } else if (condition instanceof AbstractTreeNodeSurrogateCondition) {
        final AbstractTreeNodeSurrogateCondition surrogateCond = (AbstractTreeNodeSurrogateCondition) condition;
        setValuesFromPMMLCompoundPredicate(pmmlNode.addNewCompoundPredicate(), surrogateCond.toPMMLPredicate());
    } else {
        throw new IllegalStateException("Unsupported condition (not implemented): " + condition.getClass().getSimpleName());
    }
}
Also used : TreeNodeColumnCondition(org.knime.base.node.mine.treeensemble2.model.TreeNodeColumnCondition) TreeNodeTrueCondition(org.knime.base.node.mine.treeensemble2.model.TreeNodeTrueCondition) AbstractTreeNodeSurrogateCondition(org.knime.base.node.mine.treeensemble2.model.AbstractTreeNodeSurrogateCondition)

Aggregations

ScoreDistribution (org.dmg.pmml.ScoreDistributionDocument.ScoreDistribution)1 NominalValueRepresentation (org.knime.base.node.mine.treeensemble2.data.NominalValueRepresentation)1 AbstractTreeNodeSurrogateCondition (org.knime.base.node.mine.treeensemble2.model.AbstractTreeNodeSurrogateCondition)1 TreeNodeColumnCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeColumnCondition)1 TreeNodeTrueCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeTrueCondition)1