Search in sources :

Example 1 with Node

use of org.dmg.pmml.NodeDocument.Node in project knime-core by knime.

the class TreeModelPMMLTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    PMML pmml = pmmlDoc.getPMML();
    TreeModelDocument.TreeModel treeModel = pmml.addNewTreeModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(spec, treeModel);
    treeModel.setModelName("DecisionTree");
    if (m_treeModel instanceof TreeModelClassification) {
        treeModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    } else if (m_treeModel instanceof TreeModelRegression) {
        treeModel.setFunctionName(MININGFUNCTION.REGRESSION);
    } else {
        throw new IllegalStateException("Unknown tree model \"" + m_treeModel.getClass().getSimpleName() + "\".");
    }
    AbstractTreeNode rootNode = m_treeModel.getRootNode();
    // set up splitCharacteristic
    if (isMultiSplitRecursive(rootNode)) {
        treeModel.setSplitCharacteristic(SplitCharacteristic.MULTI_SPLIT);
    } else {
        treeModel.setSplitCharacteristic(SplitCharacteristic.BINARY_SPLIT);
    }
    // ----------------------------------------------
    // set up missing value strategy
    treeModel.setMissingValueStrategy(MISSINGVALUESTRATEGY.NONE);
    // -------------------------------------------------
    // set up no true child strategy
    treeModel.setNoTrueChildStrategy(NOTRUECHILDSTRATEGY.RETURN_LAST_PREDICTION);
    // --------------------------------------------------
    // set up tree node
    NodeDocument.Node rootPMMLNode = treeModel.addNewNode();
    addTreeNode(rootPMMLNode, rootNode);
    return TreeModelDocument.TreeModel.type;
}
Also used : Node(org.dmg.pmml.NodeDocument.Node) PMML(org.dmg.pmml.PMMLDocument.PMML) NodeDocument(org.dmg.pmml.NodeDocument) TreeModelDocument(org.dmg.pmml.TreeModelDocument)

Example 2 with Node

use of org.dmg.pmml.NodeDocument.Node in project knime-core by knime.

the class PMMLDecisionTreeTranslator method exportTo.

/**
 * {@inheritDoc}
 */
@Override
public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
    m_nameMapper = new DerivedFieldMapper(pmmlDoc);
    PMML pmml = pmmlDoc.getPMML();
    TreeModelDocument.TreeModel treeModel = pmml.addNewTreeModel();
    PMMLMiningSchemaTranslator.writeMiningSchema(spec, treeModel);
    treeModel.setModelName("DecisionTree");
    if (m_isClassification) {
        treeModel.setFunctionName(MININGFUNCTION.CLASSIFICATION);
    } else {
        treeModel.setFunctionName(MININGFUNCTION.REGRESSION);
    }
    // set up splitCharacteristic
    if (treeIsMultisplit(m_tree.getRootNode())) {
        treeModel.setSplitCharacteristic(SplitCharacteristic.MULTI_SPLIT);
    } else {
        treeModel.setSplitCharacteristic(SplitCharacteristic.BINARY_SPLIT);
    }
    // ----------------------------------------------
    // set up missing value strategy
    PMMLMissingValueStrategy mvStrategy = m_tree.getMVStrategy() != null ? m_tree.getMVStrategy() : PMMLMissingValueStrategy.NONE;
    treeModel.setMissingValueStrategy(MV_STRATEGY_TO_PMML_MAP.get(mvStrategy));
    // -------------------------------------------------
    // set up no true child strategy
    PMMLNoTrueChildStrategy ntcStrategy = m_tree.getNTCStrategy();
    if (PMMLNoTrueChildStrategy.RETURN_LAST_PREDICTION.equals(ntcStrategy)) {
        treeModel.setNoTrueChildStrategy(NOTRUECHILDSTRATEGY.RETURN_LAST_PREDICTION);
    } else if (PMMLNoTrueChildStrategy.RETURN_NULL_PREDICTION.equals(ntcStrategy)) {
        treeModel.setNoTrueChildStrategy(NOTRUECHILDSTRATEGY.RETURN_NULL_PREDICTION);
    }
    // --------------------------------------------------
    // set up tree node
    NodeDocument.Node rootNode = treeModel.addNewNode();
    addTreeNode(rootNode, m_tree.getRootNode(), new DerivedFieldMapper(pmmlDoc));
    return TreeModel.type;
}
Also used : DerivedFieldMapper(org.knime.core.node.port.pmml.preproc.DerivedFieldMapper) Node(org.dmg.pmml.NodeDocument.Node) PMML(org.dmg.pmml.PMMLDocument.PMML) DecisionTreeNodeSplitPMML(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML) TreeModel(org.dmg.pmml.TreeModelDocument.TreeModel) NodeDocument(org.dmg.pmml.NodeDocument) TreeModelDocument(org.dmg.pmml.TreeModelDocument)

Example 3 with Node

use of org.dmg.pmml.NodeDocument.Node in project knime-core by knime.

the class AbstractRegressionContentParser method createNode.

@Override
public final TreeNodeRegression createNode(final Node node, final TargetColumnHelper<TreeTargetNumericColumnMetaData> targetHelper, final TreeNodeSignature signature, final List<TreeNodeRegression> children) {
    double mean = Double.parseDouble(node.getScore());
    OptionalDouble totalSum = node.getExtensionList().stream().filter(e -> e.getName().equals(TranslationUtil.TOTAL_SUM_KEY)).mapToDouble(e -> Double.parseDouble(e.getValue())).findFirst();
    OptionalDouble sumSquaredDeviation = node.getExtensionList().stream().filter(e -> e.getName().equals(TranslationUtil.SUM_SQUARED_DEVIATION_KEY)).mapToDouble(e -> Double.parseDouble(e.getValue())).findFirst();
    return createNodeInternal(node, targetHelper.getMetaData(), signature, mean, totalSum.orElse(-1), sumSquaredDeviation.orElse(-1), children.toArray(new TreeNodeRegression[children.size()]));
}
Also used : List(java.util.List) TreeTargetNumericColumnMetaData(org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData) TreeNodeSignature(org.knime.base.node.mine.treeensemble2.model.TreeNodeSignature) TreeNodeRegression(org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression) OptionalDouble(java.util.OptionalDouble) Node(org.dmg.pmml.NodeDocument.Node) TreeNodeRegression(org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression) OptionalDouble(java.util.OptionalDouble)

Example 4 with Node

use of org.dmg.pmml.NodeDocument.Node in project knime-core by knime.

the class AbstractTreeModelExporter method writeModelToPMML.

/**
 * Writes the KNIME tree model to a PMML tree model.
 * @param treeModel the PMML node which should be filled with the KNIME model
 * @param spec the {@link PMMLPortObjectSpec} of the full PMML document
 * @return the {@link SchemaType} of the tree model
 */
public SchemaType writeModelToPMML(final TreeModel treeModel, final PMMLPortObjectSpec spec) {
    checkColumnTypes(spec);
    PMMLMiningSchemaTranslator.writeMiningSchema(reduceSpec(spec), treeModel);
    treeModel.setModelName("DecisionTree");
    treeModel.setFunctionName(getMiningFunction());
    T rootNode = m_treeModel.getRootNode();
    // set up splitCharacteristic
    if (isMultiSplitRecursive(rootNode)) {
        treeModel.setSplitCharacteristic(SplitCharacteristic.MULTI_SPLIT);
    } else {
        treeModel.setSplitCharacteristic(SplitCharacteristic.BINARY_SPLIT);
    }
    // ----------------------------------------------
    // set up missing value strategy
    treeModel.setMissingValueStrategy(MISSINGVALUESTRATEGY.NONE);
    // -------------------------------------------------
    // set up no true child strategy
    treeModel.setNoTrueChildStrategy(NOTRUECHILDSTRATEGY.RETURN_LAST_PREDICTION);
    // --------------------------------------------------
    // set up tree node
    NodeDocument.Node rootPMMLNode = treeModel.addNewNode();
    addTreeNode(rootPMMLNode, rootNode);
    return TreeModelDocument.TreeModel.type;
}
Also used : Node(org.dmg.pmml.NodeDocument.Node) NodeDocument(org.dmg.pmml.NodeDocument)

Example 5 with Node

use of org.dmg.pmml.NodeDocument.Node in project knime-core by knime.

the class TreeModelImporter method importFromPMML.

/**
 * Imports an {@link AbstractTreeModel} from PMML.
 *
 * @param treeModel PMML tree model to import
 * @return a {@link AbstractTreeModel} initialized from <b>treeModel</b>
 */
public M importFromPMML(final TreeModel treeModel) {
    Node rootNode = treeModel.getNode();
    N root = createNodeFromPMML(rootNode, m_signatureFactory.getRootSignature());
    return m_treeFactory.createTree(root);
}
Also used : AbstractTreeNode(org.knime.base.node.mine.treeensemble2.model.AbstractTreeNode) Node(org.dmg.pmml.NodeDocument.Node)

Aggregations

Node (org.dmg.pmml.NodeDocument.Node)9 NodeDocument (org.dmg.pmml.NodeDocument)4 PMML (org.dmg.pmml.PMMLDocument.PMML)3 TreeModelDocument (org.dmg.pmml.TreeModelDocument)3 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)2 DecisionTreeNodeSplitPMML (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeSplitPMML)2 AbstractTreeNode (org.knime.base.node.mine.treeensemble2.model.AbstractTreeNode)2 TreeNodeSignature (org.knime.base.node.mine.treeensemble2.model.TreeNodeSignature)2 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OptionalDouble (java.util.OptionalDouble)1 Enum (org.dmg.pmml.MININGFUNCTION.Enum)1 MiningField (org.dmg.pmml.MiningFieldDocument.MiningField)1 TreeModel (org.dmg.pmml.TreeModelDocument.TreeModel)1 DecisionTree (org.knime.base.node.mine.decisiontree2.model.DecisionTree)1 DecisionTreeNodeLeaf (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNodeLeaf)1 TreeTargetNumericColumnMetaData (org.knime.base.node.mine.treeensemble2.data.TreeTargetNumericColumnMetaData)1 TreeNodeCondition (org.knime.base.node.mine.treeensemble2.model.TreeNodeCondition)1 TreeNodeRegression (org.knime.base.node.mine.treeensemble2.model.TreeNodeRegression)1