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