Search in sources :

Example 1 with Enum

use of org.dmg.pmml.MININGFUNCTION.Enum in project knime-core by knime.

the class PMMLDecisionTreeTranslator method parseDecTreeFromModel.

/**
 * Builds a decision tree object out of the TreeModel.
 * @param treeModel treeModel parsed from the PMML.
 *
 * @return DecisionTreeModel for further processing.
 */
public DecisionTree parseDecTreeFromModel(final TreeModel treeModel) {
    // --------------------------------------------
    // check the mining function, only classification is allowed
    final Enum functionName = CheckUtils.checkArgumentNotNull(treeModel.getFunctionName(), "Function name must not be null");
    if (MININGFUNCTION.CLASSIFICATION.equals(functionName)) {
        m_isClassification = true;
    } else if (MININGFUNCTION.REGRESSION.equals(functionName)) {
        m_isClassification = false;
    } else {
        throw new IllegalArgumentException("Unsupported function name \"" + functionName + "\"");
    }
    // --------------------------------------------
    // Find the predicted field from the mining schema
    MiningField[] miningFields = treeModel.getMiningSchema().getMiningFieldArray();
    String predictedField = "predictedField";
    for (MiningField mf : miningFields) {
        if (FIELDUSAGETYPE.PREDICTED == mf.getUsageType() || FIELDUSAGETYPE.TARGET == mf.getUsageType()) {
            predictedField = mf.getName();
            break;
        }
    }
    // ------------------------------------------------
    // Parse PMML nodes to KNIME nodes
    Node pmmlRoot = treeModel.getNode();
    DecisionTreeNode knimeRoot = addKnimeTreeNode(pmmlRoot);
    // ------------------------------------------------
    // parse no true child strategy
    PMMLNoTrueChildStrategy ntcStrategy = PMMLNoTrueChildStrategy.RETURN_NULL_PREDICTION;
    if (NOTRUECHILDSTRATEGY.RETURN_LAST_PREDICTION.equals(treeModel.getNoTrueChildStrategy())) {
        ntcStrategy = PMMLNoTrueChildStrategy.RETURN_LAST_PREDICTION;
    }
    // initialize a KNIME decision tree
    return new DecisionTree(knimeRoot, predictedField, MV_STRATEGY_TO_KNIME_MAP.get(treeModel.getMissingValueStrategy()), ntcStrategy);
}
Also used : Enum(org.dmg.pmml.MININGFUNCTION.Enum) MiningField(org.dmg.pmml.MiningFieldDocument.MiningField) DecisionTree(org.knime.base.node.mine.decisiontree2.model.DecisionTree) Node(org.dmg.pmml.NodeDocument.Node) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode) DecisionTreeNode(org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)

Aggregations

Enum (org.dmg.pmml.MININGFUNCTION.Enum)1 MiningField (org.dmg.pmml.MiningFieldDocument.MiningField)1 Node (org.dmg.pmml.NodeDocument.Node)1 DecisionTree (org.knime.base.node.mine.decisiontree2.model.DecisionTree)1 DecisionTreeNode (org.knime.base.node.mine.decisiontree2.model.DecisionTreeNode)1