} else { prediction = new NumericPrediction(Double.parseDouble(root.getScore()), (int) Math.round(root.getRecordCount()));
@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()); }
Node leftChild = children.get(1); assertInstanceOf(leftChild.getPredicate(), True.class); assertEquals(node.getRecordCount().doubleValue(), leftChild.getRecordCount() + rightChild.getRecordCount()); assertEquals(node.getId() + "+", rightChild.getId()); assertEquals(node.getId() + "-", leftChild.getId());
@Override public int compare(Node left, Node right){ return this.ordering.compare(left.getRecordCount(), right.getRecordCount()); } };
@Override public int compare(Node left, Node right){ return this.ordering.compare(left.getRecordCount(), right.getRecordCount()); } };
@Override public VisitorAction visit(Node node){ Deque<PMMLObject> parents = getParents(); int depth = 0; Iterator<PMMLObject> it = parents.iterator(); while(true){ PMMLObject parent = it.next(); if(parent instanceof Node){ depth++; continue; } TreeModel treeModel = (TreeModel)parent; Segment segment = (Segment)it.next(); Double recordCount = node.getRecordCount(); if(recordCount == null){ recordCount = 0d; } printRow(segment.getId(), node.getId(), recordCount, depth); break; } return super.visit(node); }
@Override public void exitNode(Node node){ Double recordCount = node.getRecordCount(); Predicate predicate = node.getPredicate(); if(recordCount != null){ node.setRecordCount(null); } // End if if(predicate instanceof True){ Node parentNode = getParentNode(); if(parentNode == null){ return; } initScore(parentNode, node); replaceChildWithGrandchildren(parentNode, node); } }
} else { prediction = new NumericPrediction(Double.parseDouble(root.getScore()), (int) Math.round(root.getRecordCount()));
static public ComplexNode toComplexNode(Node node){ ComplexNode result = new ComplexNode() .setId(node.getId()) .setScore(node.getScore()) .setRecordCount(node.getRecordCount()) .setDefaultChild(node.getDefaultChild()) .setPredicate(node.getPredicate()); if(node.hasNodes()){ (result.getNodes()).addAll(node.getNodes()); } // End if if(node.hasScoreDistributions()){ (result.getScoreDistributions()).addAll(node.getScoreDistributions()); } return result; } }
Double recordCount = node.getRecordCount();
value.setRecordCount(node.getRecordCount()); value.setDefaultChild(node.getDefaultChild());
value.setRecordCount(node.getRecordCount()); value.setDefaultChild(node.getDefaultChild());