当前位置: 首页>>代码示例>>Java>>正文


Java Node.addScoreDistributions方法代码示例

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


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

示例1: encodeClassificationScore

import org.dmg.pmml.tree.Node; //导入方法依赖的package包/类
static
private Node encodeClassificationScore(Node node, RDoubleVector probabilities, Schema schema){
	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	if(categoricalLabel.size() != probabilities.size()){
		throw new IllegalArgumentException();
	}

	Double maxProbability = null;

	for(int i = 0; i < categoricalLabel.size(); i++){
		String value = categoricalLabel.getValue(i);
		Double probability = probabilities.getValue(i);

		if(maxProbability == null || (maxProbability).compareTo(probability) < 0){
			node.setScore(value);

			maxProbability = probability;
		}

		ScoreDistribution scoreDistribution = new ScoreDistribution(value, probability);

		node.addScoreDistributions(scoreDistribution);
	}

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

示例2: buildDummyClassificationModel

import org.dmg.pmml.tree.Node; //导入方法依赖的package包/类
private static PMML buildDummyClassificationModel(int numTrees) {
  PMML pmml = PMMLUtils.buildSkeletonPMML();

  List<DataField> dataFields = new ArrayList<>();
  DataField predictor =
      new DataField(FieldName.create("color"), OpType.CATEGORICAL, DataType.STRING);
  predictor.addValues(new Value("yellow"), new Value("red"));
  dataFields.add(predictor);
  DataField target =
      new DataField(FieldName.create("fruit"), OpType.CATEGORICAL, DataType.STRING);
  target.addValues(new Value("banana"), new Value("apple"));
  dataFields.add(target);
  DataDictionary dataDictionary =
      new DataDictionary(dataFields).setNumberOfFields(dataFields.size());
  pmml.setDataDictionary(dataDictionary);

  List<MiningField> miningFields = new ArrayList<>();
  MiningField predictorMF = new MiningField(FieldName.create("color"))
      .setOpType(OpType.CATEGORICAL)
      .setUsageType(MiningField.UsageType.ACTIVE)
      .setImportance(0.5);
  miningFields.add(predictorMF);
  MiningField targetMF = new MiningField(FieldName.create("fruit"))
      .setOpType(OpType.CATEGORICAL)
      .setUsageType(MiningField.UsageType.PREDICTED);
  miningFields.add(targetMF);
  MiningSchema miningSchema = new MiningSchema(miningFields);

  double dummyCount = 2.0;
  Node rootNode = new Node().setId("r").setRecordCount(dummyCount).setPredicate(new True());

  double halfCount = dummyCount / 2;

  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")));
  right.addScoreDistributions(new ScoreDistribution("banana", halfCount));

  rootNode.addNodes(right, left);

  TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, miningSchema, rootNode)
      .setSplitCharacteristic(TreeModel.SplitCharacteristic.BINARY_SPLIT)
      .setMissingValueStrategy(TreeModel.MissingValueStrategy.DEFAULT_CHILD);

  if (numTrees > 1) {
    MiningModel miningModel = new MiningModel(MiningFunction.CLASSIFICATION, miningSchema);
    List<Segment> segments = new ArrayList<>();
    for (int i = 0; i < numTrees; i++) {
      segments.add(new Segment()
          .setId(Integer.toString(i))
          .setPredicate(new True())
          .setModel(treeModel)
          .setWeight(1.0));
    }
    miningModel.setSegmentation(
        new Segmentation(Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE, segments));
    pmml.addModels(miningModel);
  } else {
    pmml.addModels(treeModel);
  }

  return pmml;
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:67,代码来源:RDFPMMLUtilsTest.java

示例3: encodeModel

import org.dmg.pmml.tree.Node; //导入方法依赖的package包/类
@Override
public TreeModel encodeModel(Schema schema){
	List<?> classes = getClasses();
	List<? extends Number> classPrior = getClassPrior();
	Object constant = getConstant();
	String strategy = getStrategy();

	ClassDictUtil.checkSize(classes, classPrior);

	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	int index;

	double[] probabilities;

	switch(strategy){
		case "constant":
			{
				index = classes.indexOf(constant);

				probabilities = new double[classes.size()];
				probabilities[index] = 1d;
			}
			break;
		case "most_frequent":
			{
				index = classPrior.indexOf(Collections.max((List)classPrior));

				probabilities = new double[classes.size()];
				probabilities[index] = 1d;
			}
			break;
		case "prior":
			{
				index = classPrior.indexOf(Collections.max((List)classPrior));

				probabilities = Doubles.toArray(classPrior);
			}
			break;
		default:
			throw new IllegalArgumentException(strategy);
	}

	Node root = new Node()
		.setPredicate(new True())
		.setScore(ValueUtil.formatValue(classes.get(index)));

	for(int i = 0; i < classes.size(); i++){
		ScoreDistribution scoreDistribution = new ScoreDistribution(ValueUtil.formatValue(classes.get(i)), probabilities[i]);

		root.addScoreDistributions(scoreDistribution);
	}

	TreeModel treeModel = new TreeModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), root)
		.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel));

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

示例4: encodeProbabilityForest

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

	final
	RStringVector levels = (RStringVector)forest.getValue("levels");

	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	ScoreEncoder scoreEncoder = new ScoreEncoder(){

		@Override
		public void encode(Node node, Number splitValue, RNumberVector<?> terminalClassCount){

			if(splitValue.doubleValue() != 0d || (terminalClassCount == null || terminalClassCount.size() != levels.size())){
				throw new IllegalArgumentException();
			}

			Double maxProbability = null;

			for(int i = 0; i < terminalClassCount.size(); i++){
				String value = levels.getValue(i);
				Double probability = ValueUtil.asDouble(terminalClassCount.getValue(i));

				if(maxProbability == null || (maxProbability).compareTo(probability) < 0){
					node.setScore(value);

					maxProbability = probability;
				}

				ScoreDistribution scoreDisctibution = new ScoreDistribution(value, probability);

				node.addScoreDistributions(scoreDisctibution);
			}
		}
	};

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

	MiningModel miningModel = new MiningModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel))
		.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.AVERAGE, treeModels))
		.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel));

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


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