TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, miningSchema, rootNode) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD);
private static void checkTreeModel(TreeModel treeModel) { assertEquals(TreeModel.SplitCharacteristic.BINARY_SPLIT, treeModel.getSplitCharacteristic()); assertEquals(TreeModel.MissingValueStrategy.DEFAULT_CHILD, treeModel.getMissingValueStrategy()); checkNode(treeModel.getNode()); }
@Test public void testReadWrite() throws Exception { Path tempModelFile = Files.createTempFile(getTempDir(), "model", ".pmml"); PMML model = buildDummyModel(); PMMLUtils.write(model, tempModelFile); assertTrue(Files.exists(tempModelFile)); PMML model2 = PMMLUtils.read(tempModelFile); List<Model> models = model2.getModels(); assertEquals(1, models.size()); assertInstanceOf(models.get(0), TreeModel.class); TreeModel treeModel = (TreeModel) models.get(0); assertEquals(123.0, treeModel.getNode().getRecordCount().doubleValue()); assertEquals(MiningFunction.CLASSIFICATION, treeModel.getMiningFunction()); }
return new TreeModel() .setNode(root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD);
public TreeModel encodeTreeModel(PredicateManager predicateManager, Schema schema){ org.dmg.pmml.tree.Node root = encodeNode(new True(), predicateManager, 0, schema); TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD) .setMathContext(MathContext.FLOAT); return treeModel; }
private TreeModel encodeTreeModel(RGenericVector tree, Schema schema){ Node root = encodeNode(new True(), tree, schema); TreeModel treeModel = new TreeModel(this.miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT); return treeModel; }
@Override public void exitTreeModel(TreeModel treeModel){ treeModel .setMissingValueStrategy(TreeModel.MissingValueStrategy.NONE) .setNoTrueChildStrategy(TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION) .setSplitCharacteristic(TreeModel.SplitCharacteristic.MULTI_SPLIT); } }
private static PMML buildDummyModel() { Node node = new Node().setRecordCount(123.0); TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, null, node); PMML pmml = PMMLUtils.buildSkeletonPMML(); pmml.addModels(treeModel); return pmml; }
TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, miningSchema, rootNode) .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT) .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD) .setMiningSchema(miningSchema);
@Override public void enterTreeModel(TreeModel treeModel){ TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy(); TreeModel.NoTrueChildStrategy noTrueChildStrategy = treeModel.getNoTrueChildStrategy(); TreeModel.SplitCharacteristic splitCharacteristic = treeModel.getSplitCharacteristic(); if(!(TreeModel.MissingValueStrategy.NONE).equals(missingValueStrategy) || !(TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION).equals(noTrueChildStrategy) || !(TreeModel.SplitCharacteristic.BINARY_SPLIT).equals(splitCharacteristic)){ throw new IllegalArgumentException(); } this.miningFunction = treeModel.getMiningFunction(); }
@Override public void enterTreeModel(TreeModel treeModel){ TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy(); TreeModel.NoTrueChildStrategy noTrueChildStrategy = treeModel.getNoTrueChildStrategy(); TreeModel.SplitCharacteristic splitCharacteristic = treeModel.getSplitCharacteristic(); if(!(TreeModel.MissingValueStrategy.DEFAULT_CHILD).equals(missingValueStrategy) || !(TreeModel.NoTrueChildStrategy.RETURN_NULL_PREDICTION).equals(noTrueChildStrategy) || !(TreeModel.SplitCharacteristic.BINARY_SPLIT).equals(splitCharacteristic)){ throw new IllegalArgumentException(); } }
static public TreeModel encodeTreeModel(byte[] compressedTree, PredicateManager predicateManager, Schema schema){ Label label = new ContinuousLabel(null, DataType.DOUBLE); AtomicInteger idSequence = new AtomicInteger(1); ByteBufferWrapper buffer = new ByteBufferWrapper(compressedTree); Node root = encodeNode(new True(), idSequence, compressedTree, buffer, predicateManager, new CategoryManager(), schema); TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(label), root) .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD); return treeModel; }
@Override public VisitorAction accept(Visitor visitor) { VisitorAction status = visitor.visit(this); if (status == VisitorAction.CONTINUE) { visitor.pushParent(this); if ((status == VisitorAction.CONTINUE)&&hasExtensions()) { status = PMMLObject.traverse(visitor, getExtensions()); } if (status == VisitorAction.CONTINUE) { status = PMMLObject.traverse(visitor, getMiningSchema(), getOutput(), getModelStats(), getModelExplanation(), getTargets(), getLocalTransformations(), getNode(), getModelVerification()); } visitor.popParent(); } if (status == VisitorAction.TERMINATE) { return VisitorAction.TERMINATE; } return VisitorAction.CONTINUE; }
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, new MiningSchema(), node1a) .setMathContext(MathContext.FLOAT); treeModel.setMiningFunction(MiningFunction.REGRESSION);
@Override public void exitTreeModel(TreeModel treeModel){ treeModel .setNoTrueChildStrategy(TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION) .setSplitCharacteristic(TreeModel.SplitCharacteristic.MULTI_SPLIT); }
private TreeModel configureTreeModel(TreeModel treeModel){ TreeModel.NoTrueChildStrategy noTrueChildStrategy = TreeModel.NoTrueChildStrategy.RETURN_LAST_PREDICTION; TreeModel.MissingValueStrategy missingValueStrategy; switch(this.useSurrogate){ case 0: missingValueStrategy = TreeModel.MissingValueStrategy.NULL_PREDICTION; // XXX break; case 1: missingValueStrategy = TreeModel.MissingValueStrategy.LAST_PREDICTION; break; case 2: missingValueStrategy = null; break; default: throw new IllegalArgumentException(); } treeModel .setNoTrueChildStrategy(noTrueChildStrategy) .setMissingValueStrategy(missingValueStrategy); return treeModel; }
TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, miningSchema, root) .setModelName("golfing");