• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Node类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.dmg.pmml.tree.Node的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Node类属于org.dmg.pmml.tree包,在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: predictorExampleCounts

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
/**
 * @param trainPointData data to run down trees
 * @param model random decision forest model to count on
 * @return map of predictor index to the number of training examples that reached a
 *  node whose decision is based on that feature. The index is among predictors, not all
 *  features, since there are fewer predictors than features. That is, the index will
 *  match the one used in the {@link RandomForestModel}.
 */
private static Map<Integer,Long> predictorExampleCounts(JavaRDD<LabeledPoint> trainPointData,
                                                        RandomForestModel model) {
  return trainPointData.mapPartitions(data -> {
      IntLongMap featureIndexCount = HashIntLongMaps.newMutableMap();
      data.forEachRemaining(datum -> {
        double[] featureVector = datum.features().toArray();
        for (DecisionTreeModel tree : model.trees()) {
          org.apache.spark.mllib.tree.model.Node node = tree.topNode();
          // This logic cloned from Node.predict:
          while (!node.isLeaf()) {
            Split split = node.split().get();
            int featureIndex = split.feature();
            // Count feature
            featureIndexCount.addValue(featureIndex, 1);
            node = nextNode(featureVector, node, split, featureIndex);
          }
        }
      });
      // Clone to avoid problem with Kryo serializing Koloboke
      return Collections.<Map<Integer,Long>>singleton(
          new HashMap<>(featureIndexCount)).iterator();
  }).reduce(RDFUpdate::merge);
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:32,代码来源:RDFUpdate.java


示例2: nextNode

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private static org.apache.spark.mllib.tree.model.Node nextNode(
    double[] featureVector,
    org.apache.spark.mllib.tree.model.Node node,
    Split split,
    int featureIndex) {
  double featureValue = featureVector[featureIndex];
  if (split.featureType().equals(FeatureType.Continuous())) {
    if (featureValue <= split.threshold()) {
      return node.leftNode().get();
    } else {
      return node.rightNode().get();
    }
  } else {
    if (split.categories().contains(featureValue)) {
      return node.leftNode().get();
    } else {
      return node.rightNode().get();
    }
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:21,代码来源:RDFUpdate.java


示例3: encodeTreeModel

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
static
public TreeModel encodeTreeModel(org.apache.spark.ml.tree.Node node, PredicateManager predicateManager, MiningFunction miningFunction, Schema schema){
	Node root = encodeNode(node, predicateManager, Collections.<FieldName, Set<String>>emptyMap(), miningFunction, schema)
		.setPredicate(new True());

	TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);

	String compact = TreeModelOptions.COMPACT;
	if(compact != null && Boolean.valueOf(compact)){
		Visitor visitor = new TreeModelCompactor();

		visitor.applyTo(treeModel);
	}

	return treeModel;
}
 
开发者ID:jpmml,项目名称:jpmml-sparkml,代码行数:18,代码来源:TreeModelUtil.java


示例4: encodeTreeModel

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
static
public <E extends Estimator & HasTree> TreeModel encodeTreeModel(E estimator, PredicateManager predicateManager, MiningFunction miningFunction, Schema schema){
	Tree tree = estimator.getTree();

	int[] leftChildren = tree.getChildrenLeft();
	int[] rightChildren = tree.getChildrenRight();
	int[] features = tree.getFeature();
	double[] thresholds = tree.getThreshold();
	double[] values = tree.getValues();

	Node root = new Node()
		.setId("1")
		.setPredicate(new True());

	encodeNode(root, predicateManager, 0, leftChildren, rightChildren, features, thresholds, values, miningFunction, schema);

	TreeModel treeModel = new TreeModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT);

	return treeModel;
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:22,代码来源:TreeModelUtil.java


示例5: encodeRegression

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private MiningModel encodeRegression(RGenericVector ranger, Schema schema){
	RGenericVector forest = (RGenericVector)ranger.getValue("forest");

	ScoreEncoder scoreEncoder = new ScoreEncoder(){

		@Override
		public void encode(Node node, Number splitValue, RNumberVector<?> terminalClassCount){
			node.setScore(ValueUtil.formatValue(splitValue));
		}
	};

	List<TreeModel> treeModels = encodeForest(forest, MiningFunction.REGRESSION, scoreEncoder, schema);

	MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()))
		.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.AVERAGE, treeModels));

	return miningModel;
}
 
开发者ID:jpmml,项目名称:jpmml-r,代码行数:19,代码来源:RangerConverter.java


示例6: process

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private void process(Node node){
	List<Node> path = new ArrayList<>();
	path.add(node);

	Deque<PMMLObject> parents = getParents();
	for(PMMLObject parent : parents){

		if(!(parent instanceof Node)){
			break;
		}

		path.add((Node)parent);
	}

	Collections.reverse(path);

	this.paths.put(node, path);
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:19,代码来源:TreePathFinder.java


示例7: evaluateNode

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private Boolean evaluateNode(Trail trail, Node node, EvaluationContext context){
	EmbeddedModel embeddedModel = node.getEmbeddedModel();
	if(embeddedModel != null){
		throw new UnsupportedElementException(embeddedModel);
	}

	Predicate predicate = PredicateUtil.ensurePredicate(node);

	// A compound predicate whose boolean operator is "surrogate" represents a special case
	if(predicate instanceof CompoundPredicate){
		CompoundPredicate compoundPredicate = (CompoundPredicate)predicate;

		PredicateUtil.CompoundPredicateResult result = PredicateUtil.evaluateCompoundPredicateInternal(compoundPredicate, context);
		if(result.isAlternative()){
			trail.addMissingLevel();
		}

		return result.getResult();
	} else

	{
		return PredicateUtil.evaluate(predicate, context);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:25,代码来源:TreeModelEvaluator.java


示例8: handleDefaultChild

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private Trail handleDefaultChild(Trail trail, Node node, EvaluationContext context){

		// "The defaultChild missing value strategy requires the presence of the defaultChild attribute in every non-leaf Node"
		String defaultChild = node.getDefaultChild();
		if(defaultChild == null){
			throw new MissingAttributeException(node, PMMLAttributes.NODE_DEFAULTCHILD);
		}

		trail.addMissingLevel();

		List<Node> children = node.getNodes();
		for(int i = 0, max = children.size(); i < max; i++){
			Node child = children.get(i);

			String id = child.getId();
			if(id != null && (id).equals(defaultChild)){
				// The predicate of the referenced Node is not evaluated
				return handleTrue(trail, child, context);
			}
		}

		// "Only Nodes which are immediate children of the respective Node can be referenced"
		throw new InvalidAttributeException(node, PMMLAttributes.NODE_DEFAULTCHILD, defaultChild);
	}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:25,代码来源:TreeModelEvaluator.java


示例9: handleNoTrueChild

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private Trail handleNoTrueChild(Trail trail){
	TreeModel treeModel = getModel();

	TreeModel.NoTrueChildStrategy noTrueChildStrategy = treeModel.getNoTrueChildStrategy();
	switch(noTrueChildStrategy){
		case RETURN_NULL_PREDICTION:
			return trail.selectNull();
		case RETURN_LAST_PREDICTION:
			Node lastPrediction = trail.getLastPrediction();

			// "Return the parent Node only if it specifies a score attribute"
			if(lastPrediction.hasScore()){
				return trail.selectLastPrediction();
			}
			return trail.selectNull();
		default:
			throw new UnsupportedAttributeException(treeModel, noTrueChildStrategy);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:20,代码来源:TreeModelEvaluator.java


示例10: handleMissingValue

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
/**
 * @param parent The parent Node of the Node that evaluated to the missing value.
 * @param node The Node that evaluated to the missing value.
 */
private Trail handleMissingValue(Trail trail, Node parent, Node node, EvaluationContext context){
	TreeModel treeModel = getModel();

	TreeModel.MissingValueStrategy missingValueStrategy = treeModel.getMissingValueStrategy();
	switch(missingValueStrategy){
		case NULL_PREDICTION:
			return trail.selectNull();
		case LAST_PREDICTION:
			return trail.selectLastPrediction();
		case DEFAULT_CHILD:
			return handleDefaultChild(trail, parent, context);
		case NONE:
			return null;
		default:
			throw new UnsupportedAttributeException(treeModel, missingValueStrategy);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:22,代码来源:TreeModelEvaluator.java


示例11: getProbability

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
@Test
public void getProbability(){
	Node node = new Node()
		.setScore("ham");

	final
	BiMap<String, Node> entityRegistry = ImmutableBiMap.of("1", node);

	NodeScoreDistribution<Double> classification = new NodeScoreDistribution<Double>(new ValueMap<String, Double>(), node){

		@Override
		public BiMap<String, Node> getEntityRegistry(){
			return entityRegistry;
		}
	};

	classification.put("ham", new DoubleValue(0.75d));
	classification.put("spam", new DoubleValue(0.25d));

	assertEquals(ImmutableSet.of("ham", "spam"), classification.getCategoryValues());

	assertEquals((Double)0.75d, classification.getProbability("ham"));
	assertEquals((Double)0.25d, classification.getProbability("spam"));
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:25,代码来源:NodeScoreDistributionTest.java


示例12: createTreeModelEvaluator

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
static
private TreeModelEvaluator createTreeModelEvaluator(MiningFunction miningFunction, MathContext mathContext, Target target){
	Node root = new Node()
		.setPredicate(new False());

	Targets targets = new Targets()
		.addTargets(target);

	TreeModel treeModel = new TreeModel(miningFunction, new MiningSchema(), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
		.setMathContext(mathContext)
		.setTargets(targets);

	PMML pmml = new PMML(Version.PMML_4_3.getVersion(), new Header(), new DataDictionary())
		.addModels(treeModel);

	return new TreeModelEvaluator(pmml);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:19,代码来源:TargetUtilTest.java


示例13: visit

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
@Override
public VisitorAction visit(Node node){
	TreeModel treeModel = getTreeModel();

	MiningFunction miningFunction = treeModel.getMiningFunction();
	switch(miningFunction){
		case REGRESSION:
			if(node.hasScoreDistributions()){
				List<ScoreDistribution> scoreDistributions = node.getScoreDistributions();

				scoreDistributions.clear();
			}
			break;
		default:
			break;
	}

	return super.visit(node);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:20,代码来源:ScoreDistributionCleaner.java


示例14: clean

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
@Test
public void clean(){
	Node node = new Node()
		.setPredicate(new True())
		.setScore("1")
		.addScoreDistributions(new ScoreDistribution("0", 0), new ScoreDistribution("1", 100));

	TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, new MiningSchema(), node);

	ScoreDistributionCleaner cleaner = new ScoreDistributionCleaner();
	cleaner.applyTo(treeModel);

	assertTrue(node.hasScoreDistributions());

	treeModel.setMiningFunction(MiningFunction.REGRESSION);

	cleaner.applyTo(treeModel);

	assertFalse(node.hasScoreDistributions());
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:21,代码来源:ScoreDistributionCleanerTest.java


示例15: intern

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
@Test
public void intern(){
	ScoreDistribution left = new ScoreDistribution("event", 0.33d);
	ScoreDistribution right = new ScoreDistribution("event", 0.33d);

	Node leftChild = createNode(left);
	Node rightChild = createNode(right);

	Node root = new Node()
		.setPredicate(new True())
		.addNodes(leftChild, rightChild);

	TreeModel treeModel = new TreeModel()
		.setNode(root);

	for(int i = 0; i < 2; i++){
		assertNotSame((leftChild.getScoreDistributions()).get(i), (rightChild.getScoreDistributions()).get(i));
	}

	intern(treeModel);

	for(int i = 0; i < 2; i++){
		assertSame((leftChild.getScoreDistributions()).get(i), (rightChild.getScoreDistributions()).get(i));
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:26,代码来源:ScoreDistributionInternerTest.java


示例16: encodeTreeModel

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
public TreeModel encodeTreeModel(PredicateManager predicateManager, Schema schema){
	Node root = new Node()
		.setPredicate(new True());

	encodeNode(root, predicateManager, Collections.<FieldName, Set<String>>emptyMap(), 0, schema);

	TreeModel treeModel = new TreeModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(schema.getLabel()), root)
		.setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
		.setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD);

	return treeModel;
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:13,代码来源:Tree.java


示例17: pushParent

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
@Override
public void pushParent(PMMLObject object){
	super.pushParent(object);

	if(object instanceof Node){
		handleNodePush((Node)object);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:9,代码来源:TreeModelCompactor.java


示例18: popParent

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
@Override
public PMMLObject popParent(){
	PMMLObject object = super.popParent();

	if(object instanceof Node){
		handleNodePop((Node)object);
	}

	return object;
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:11,代码来源:TreeModelCompactor.java


示例19: handleNodePop

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private void handleNodePop(Node node){
	Double recordCount = node.getRecordCount();
	String score = node.getScore();
	Predicate predicate = node.getPredicate();

	if(recordCount != null){
		node.setRecordCount(null);
	} // End if

	if(predicate instanceof True){
		Node parentNode = getParentNode();

		if(parentNode == null){
			return;
		}

		String parentScore = parentNode.getScore();
		if(parentScore != null){
			throw new IllegalArgumentException();
		}

		parentNode.setScore(score);

		List<Node> parentChildren = parentNode.getNodes();

		boolean success = parentChildren.remove(node);
		if(!success){
			throw new IllegalArgumentException();
		} // End if

		if(node.hasNodes()){
			List<Node> children = node.getNodes();

			parentChildren.addAll(children);
		}
	}
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:38,代码来源:TreeModelCompactor.java


示例20: getParentNode

import org.dmg.pmml.tree.Node; //导入依赖的package包/类
private Node getParentNode(){
	Deque<PMMLObject> parents = getParents();

	PMMLObject parent = parents.peekFirst();
	if(parent instanceof Node){
		return (Node)parent;
	}

	return null;
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:11,代码来源:TreeModelCompactor.java



注:本文中的org.dmg.pmml.tree.Node类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Minecraft类代码示例发布时间:2022-05-23
下一篇:
Java QueryResultIterable类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap