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);
}
Aggregations