Java Code Examples for org.dmg.pmml.tree.Node#getScore()
The following examples show how to use
org.dmg.pmml.tree.Node#getScore() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeModelEvaluator.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
private <V extends Number> NodeScore<V> createNodeScore(ValueFactory<V> valueFactory, TargetField targetField, Node node){ Object score = node.getScore(); Value<V> value; if(score instanceof Number){ value = valueFactory.newValue((Number)score); } else { value = valueFactory.newValue((String)score); } value = TargetUtil.evaluateRegressionInternal(targetField, value); NodeScore<V> result = new NodeScore<V>(value, node){ @Override public BiMap<String, Node> getEntityRegistry(){ return TreeModelEvaluator.this.getEntityRegistry(); } @Override public List<Node> getDecisionPath(){ return TreeModelEvaluator.this.getPath(getNode()); } }; return result; }
Example 2
Source File: NodeScoreParser.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 5 votes |
@Override public VisitorAction visit(Node node){ if(node.hasScore()){ Object score = node.getScore(); if(score instanceof String){ score = parseScore(score); node.setScore(score); } } return super.visit(node); }
Example 3
Source File: TreeModelCompactor.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 4 votes |
@Override public void enterNode(Node node){ Object id = node.getId(); Object score = node.getScore(); Object defaultChild = node.getDefaultChild(); if(id == null){ throw new IllegalArgumentException(); } // End if if(node.hasNodes()){ List<Node> children = node.getNodes(); if(children.size() != 2 || score != null || defaultChild == null){ throw new IllegalArgumentException(); } Node firstChild = children.get(0); Node secondChild = children.get(1); if(equalsNode(defaultChild, firstChild)){ children = swapChildren(node); firstChild = children.get(0); secondChild = children.get(1); } else if(equalsNode(defaultChild, secondChild)){ // Ignored } else { throw new IllegalArgumentException(); } node.setDefaultChild(null); secondChild.setPredicate(True.INSTANCE); } else { if(score == null || defaultChild != null){ throw new IllegalArgumentException(); } } node.setId(null); }
Example 4
Source File: TreeModelCompactor.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 4 votes |
@Override public void enterNode(Node node){ Object id = node.getId(); Object score = node.getScore(); if(id != null){ throw new IllegalArgumentException(); } // End if if(node.hasNodes()){ List<Node> children = node.getNodes(); if(children.size() != 2 || score != null){ throw new IllegalArgumentException(); } Node firstChild = children.get(0); Node secondChild = children.get(1); Predicate firstPredicate = firstChild.getPredicate(); Predicate secondPredicate = secondChild.getPredicate(); checkFieldReference(firstPredicate, secondPredicate); boolean update = true; if(hasOperator(firstPredicate, SimplePredicate.Operator.EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){ update = isCategoricalField((SimplePredicate)firstPredicate); } else if(hasOperator(firstPredicate, SimplePredicate.Operator.NOT_EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){ children = swapChildren(node); firstChild = children.get(0); secondChild = children.get(1); } else if(hasOperator(firstPredicate, SimplePredicate.Operator.EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.NOT_EQUAL)){ // Ignored } else if(hasOperator(firstPredicate, SimplePredicate.Operator.LESS_OR_EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.GREATER_THAN)){ // Ignored } else if(hasOperator(firstPredicate, SimplePredicate.Operator.EQUAL) && hasBooleanOperator(secondPredicate, SimpleSetPredicate.BooleanOperator.IS_IN)){ addCategoricalField(secondChild); } else if(hasBooleanOperator(firstPredicate, SimpleSetPredicate.BooleanOperator.IS_IN) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){ children = swapChildren(node); firstChild = children.get(0); secondChild = children.get(1); addCategoricalField(secondChild); } else if(hasBooleanOperator(firstPredicate, SimpleSetPredicate.BooleanOperator.IS_IN) && hasBooleanOperator(secondPredicate, SimpleSetPredicate.BooleanOperator.IS_IN)){ addCategoricalField(secondChild); } else { throw new IllegalArgumentException(); } // End if if(update){ secondChild.setPredicate(True.INSTANCE); } } else { if(score == null){ throw new IllegalArgumentException(); } } }
Example 5
Source File: TreeModelCompactor.java From jpmml-xgboost with GNU Affero General Public License v3.0 | 4 votes |
@Override public void enterNode(Node node){ Object id = node.getId(); Object score = node.getScore(); Object defaultChild = node.getDefaultChild(); if(id == null){ throw new IllegalArgumentException(); } // End if if(node.hasNodes()){ List<Node> children = node.getNodes(); if(children.size() != 2 || score != null || defaultChild == null){ throw new IllegalArgumentException(); } Node firstChild = children.get(0); Node secondChild = children.get(1); if(equalsNode(defaultChild, firstChild)){ children = swapChildren(node); firstChild = children.get(0); secondChild = children.get(1); } else if(equalsNode(defaultChild, secondChild)){ // Ignored } else { throw new IllegalArgumentException(); } node.setDefaultChild(null); secondChild.setPredicate(True.INSTANCE); } else { if(score == null || defaultChild != null){ throw new IllegalArgumentException(); } } node.setId(null); }
Example 6
Source File: TreeModelCompactor.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
@Override public void enterNode(Node node){ Object id = node.getId(); Object score = node.getScore(); if(id == null){ throw new IllegalArgumentException(); } // End if if(node.hasNodes()){ List<Node> children = node.getNodes(); if(children.size() != 2){ throw new IllegalArgumentException(); } Node firstChild = children.get(0); Node secondChild = children.get(1); Predicate firstPredicate = firstChild.getPredicate(); Predicate secondPredicate = secondChild.getPredicate(); checkFieldReference(firstPredicate, secondPredicate); checkValue(firstPredicate, secondPredicate); if(hasOperator(firstPredicate, SimplePredicate.Operator.NOT_EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){ children = swapChildren(node); firstChild = children.get(0); secondChild = children.get(1); } else if(hasOperator(firstPredicate, SimplePredicate.Operator.LESS_OR_EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.GREATER_THAN)){ // Ignored } else { throw new IllegalArgumentException(); } secondChild.setPredicate(True.INSTANCE); } else { if(score == null){ throw new IllegalArgumentException(); } } node.setId(null); }
Example 7
Source File: RandomForestCompactor.java From jpmml-r with GNU Affero General Public License v3.0 | 4 votes |
@Override public void enterNode(Node node){ Object id = node.getId(); Object score = node.getScore(); if(id == null){ throw new IllegalArgumentException(); } // End if if(node.hasNodes()){ List<Node> children = node.getNodes(); if(children.size() != 2 || score != null){ throw new IllegalArgumentException(); } Node firstChild = children.get(0); Node secondChild = children.get(1); Predicate firstPredicate = firstChild.getPredicate(); Predicate secondPredicate = secondChild.getPredicate(); checkFieldReference(firstPredicate, secondPredicate); boolean update = isDefinedField((HasFieldReference<?>)firstPredicate); if(hasOperator(firstPredicate, SimplePredicate.Operator.EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){ // Ignored } else if(hasOperator(firstPredicate, SimplePredicate.Operator.LESS_OR_EQUAL) && hasOperator(secondPredicate, SimplePredicate.Operator.GREATER_THAN)){ update = true; } else if(hasOperator(firstPredicate, SimplePredicate.Operator.EQUAL) && hasBooleanOperator(secondPredicate, SimpleSetPredicate.BooleanOperator.IS_IN)){ // Ignored } else if(hasBooleanOperator(firstPredicate, SimpleSetPredicate.BooleanOperator.IS_IN) && hasOperator(secondPredicate, SimplePredicate.Operator.EQUAL)){ if(update){ children = swapChildren(node); firstChild = children.get(0); secondChild = children.get(1); } } else if(hasBooleanOperator(firstPredicate, SimpleSetPredicate.BooleanOperator.IS_IN) && hasBooleanOperator(secondPredicate, SimpleSetPredicate.BooleanOperator.IS_IN)){ // Ignored } else { throw new IllegalArgumentException(); } // End if if(update){ secondChild.setPredicate(True.INSTANCE); } } else { if(score == null){ throw new IllegalArgumentException(); } } node.setId(null); }