modelNode.setPredicate(predicate);
Node rootNode = new Node().setId("r").setRecordCount(dummyCount).setPredicate(new True()); .setId("r-") .setRecordCount(halfCount) .setPredicate(new True()) .setScore("-2.0"); Node right = new Node().setId("r+").setRecordCount(halfCount) .setPredicate(new SimplePredicate(FieldName.create("foo"), SimplePredicate.Operator.GREATER_THAN).setValue("3.14")) .setScore("2.0");
Node rootNode = new Node().setId("r").setRecordCount(dummyCount).setPredicate(new True()); Node left = new Node().setId("r-").setRecordCount(halfCount).setPredicate(new True()); left.addScoreDistributions(new ScoreDistribution("apple", halfCount)); Node right = new Node().setId("r+").setRecordCount(halfCount) .setPredicate(new SimpleSetPredicate(FieldName.create("color"), SimpleSetPredicate.BooleanOperator.IS_NOT_IN, new Array(Array.Type.STRING, "red")));
secondChild.setPredicate(new True()); } else
secondChild.setPredicate(new True()); } else
secondChild.setPredicate(new True()); } else
private void makeDefault(Node node){ Predicate predicate = node.getPredicate(); CompoundPredicate compoundPredicate; if(predicate instanceof CompoundPredicate){ compoundPredicate = (CompoundPredicate)predicate; } else { compoundPredicate = new CompoundPredicate(CompoundPredicate.BooleanOperator.SURROGATE) .addPredicates(predicate); node.setPredicate(compoundPredicate); } compoundPredicate.addPredicates(new True()); }
secondChild.setPredicate(new True()); } else
secondChild.setPredicate(new True());
static private <M extends Model<M> & DecisionTreeModel> TreeModel encodeTreeModel(M model, PredicateManager predicateManager, MiningFunction miningFunction, ScoreEncoder scoreEncoder, Schema schema){ Node root = new Node() .setPredicate(new True()); encodeNode(root, model.rootNode(), predicateManager, new CategoryManager(), scoreEncoder, schema); TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT); return treeModel; }
public TreeModel encodeTreeModel(Schema schema){ org.dmg.pmml.tree.Node root = new org.dmg.pmml.tree.Node() .setPredicate(new True()); encodeNode(root, 0, schema); TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMissingValueStrategy(TreeModel.MissingValueStrategy.NONE) .setMathContext(MathContext.FLOAT); return treeModel; }
secondChild.setPredicate(new True());
private void encodeNode(org.dmg.pmml.tree.Node parent, int index, Schema schema){ parent.setId(String.valueOf(index + 1)); Node node = allNodes.get(index); if(!node.isLeaf()){ int splitIndex = node.getFeatureIndex(); Feature feature = schema.getFeature(splitIndex); org.dmg.pmml.tree.Node leftChild = new org.dmg.pmml.tree.Node() .setPredicate(encodePredicate(feature, node, true)); encodeNode(leftChild, node.getLeftChild().getId(), schema); org.dmg.pmml.tree.Node rightChild = new org.dmg.pmml.tree.Node() .setPredicate(encodePredicate(feature, node, false)); encodeNode(rightChild, node.getRightChild().getId(), schema); parent.addNodes(leftChild, rightChild); boolean defaultLeft = false; parent.setDefaultChild(defaultLeft ? leftChild.getId() : rightChild.getId()); } else { float value = (float)node.getValue(); parent.setScore(ValueUtil.formatValue(value)); } }
.setPredicate(leftPredicate); .setPredicate(rightPredicate);
.setPredicate(predicate) .addNodes(leftChild, rightChild); .setScore(this.leaf_value_[index]) .setRecordCount((double)this.leaf_count_[index]) .setPredicate(predicate);
.setPredicate(predicate) .addNodes(leftChild, rightChild);
.setPredicate(predicate) .addNodes(leftChild, rightChild);
@Override public Node unmarshal(ComplexNode value){ if(value.getRecordCount() != null){ return value; } // End if if(value.hasExtensions() || (value.getPartition() != null) || value.hasScoreDistributions() || (value.getEmbeddedModel() != null)){ return value; } Node node; if(value.hasNodes()){ node = new BranchNode() .setId(value.getId()) .setDefaultChild(value.getDefaultChild()); (node.getNodes()).addAll(value.getNodes()); } else { node = new LeafNode() .setId(value.getId()); } node .setScore(value.getScore()) .setPredicate(value.getPredicate()); return node; }
@Override public Node unmarshal(ComplexNode value){ if(value.getRecordCount() != null){ return value; } // End if if(value.hasExtensions() || (value.getPartition() != null) || value.hasScoreDistributions() || (value.getEmbeddedModel() != null)){ return value; } Node node; if(value.hasNodes()){ node = new BranchNode() .setId(value.getId()) .setDefaultChild(value.getDefaultChild()); (node.getNodes()).addAll(value.getNodes()); } else { node = new LeafNode() .setId(value.getId()); } node .setScore(value.getScore()) .setPredicate(value.getPredicate()); return node; }
.setId(id) .setDefaultChild(leftward ? leftChild.getId() : rightChild.getId()) .setPredicate(predicate) .addNodes(leftChild, rightChild);