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


Java Segmentation.MultipleModelMethod方法代码示例

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


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

示例1: createNestedOutputFields

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
private List<OutputField> createNestedOutputFields(){
	MiningModel miningModel = getModel();

	Segmentation segmentation = miningModel.getSegmentation();

	List<Segment> segments = segmentation.getSegments();

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case SELECT_ALL:
			// Ignored
			break;
		case SELECT_FIRST:
			return createNestedOutputFields(getActiveHead(segments));
		case MODEL_CHAIN:
			return createNestedOutputFields(getActiveTail(segments));
		default:
			break;
	}

	return Collections.emptyList();
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:23,代码来源:MiningModelEvaluator.java

示例2: encodeModel

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
@Override
public MiningModel encodeModel(Schema schema){
	List<? extends Classifier> estimators = getEstimators();
	List<List<Integer>> estimatorsFeatures = getEstimatorsFeatures();

	Segmentation.MultipleModelMethod multipleModelMethod = Segmentation.MultipleModelMethod.AVERAGE;

	for(Classifier estimator : estimators){

		if(!estimator.hasProbabilityDistribution()){
			multipleModelMethod = Segmentation.MultipleModelMethod.MAJORITY_VOTE;

			break;
		}
	}

	MiningModel miningModel = BaggingUtil.encodeBagging(estimators, estimatorsFeatures, multipleModelMethod, MiningFunction.CLASSIFICATION, schema)
		.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, (CategoricalLabel)schema.getLabel()));

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

示例3: getDataField

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
@Override
protected DataField getDataField(){
	MiningModel miningModel = getModel();

	Segmentation segmentation = miningModel.getSegmentation();

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case SELECT_ALL:
		case SELECT_FIRST:
		case MODEL_CHAIN:
			return null;
		default:
			return super.getDataField();
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:17,代码来源:MiningModelEvaluator.java

示例4: createSegmentation

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
static
public Segmentation createSegmentation(Segmentation.MultipleModelMethod multipleModelMethod, List<? extends Model> models, List<? extends Number> weights){

	if((weights != null) && (models.size() != weights.size())){
		throw new IllegalArgumentException();
	}

	List<Segment> segments = new ArrayList<>();

	for(int i = 0; i < models.size(); i++){
		Model model = models.get(i);
		Number weight = (weights != null ? weights.get(i) : null);

		Segment segment = new Segment()
			.setId(String.valueOf(i + 1))
			.setPredicate(new True())
			.setModel(model);

		if(weight != null && !ValueUtil.isOne(weight)){
			segment.setWeight(ValueUtil.asDouble(weight));
		}

		segments.add(segment);
	}

	return new Segmentation(multipleModelMethod, segments);
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:28,代码来源:MiningModelUtil.java

示例5: encodeBaseForest

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
static
public <E extends Estimator & HasEstimatorEnsemble<T> & HasTreeOptions, T extends Estimator & HasTree> MiningModel encodeBaseForest(E estimator, Segmentation.MultipleModelMethod multipleModelMethod, MiningFunction miningFunction, Schema schema){
	List<TreeModel> treeModels = TreeModelUtil.encodeTreeModelSegmentation(estimator, miningFunction, schema);

	MiningModel miningModel = new MiningModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()))
		.setSegmentation(MiningModelUtil.createSegmentation(multipleModelMethod, treeModels));

	return TreeModelUtil.transform(estimator, miningModel);
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:10,代码来源:BaseForestUtil.java

示例6: parseVoting

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
static
private Segmentation.MultipleModelMethod parseVoting(String voting, boolean weighted){

	switch(voting){
		case "hard":
			return (weighted ? Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE : Segmentation.MultipleModelMethod.MAJORITY_VOTE);
		case "soft":
			return (weighted ? Segmentation.MultipleModelMethod.WEIGHTED_AVERAGE : Segmentation.MultipleModelMethod.AVERAGE);
		default:
			throw new IllegalArgumentException(voting);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:13,代码来源:VotingClassifier.java

示例7: createSegmentation

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
static
public Segmentation createSegmentation(Segmentation.MultipleModelMethod multipleModelMethod, List<? extends Model> models, List<? extends Number> weights){

    if((weights != null) && (models.size() != weights.size())){
        throw new IllegalArgumentException();
    }

    List<Segment> segments = new ArrayList<>();

    for(int i = 0; i < models.size(); i++){
        Model model = models.get(i);
        Number weight = (weights != null ? weights.get(i) : null);

        Segment segment = new Segment()
                .setId(String.valueOf(i + 1))
                .setPredicate(new True())
                .setModel(model);

        if(weight != null && !ValueUtil.isOne(weight)){
            segment.setWeight(ValueUtil.asDouble(weight));
        }

        segments.add(segment);
    }

    return new Segmentation(multipleModelMethod, segments);
}
 
开发者ID:cheng-li,项目名称:pyramid,代码行数:28,代码来源:MiningModelUtil.java

示例8: getEarlierOutputs

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
static
private List<Output> getEarlierOutputs(Segmentation segmentation, Segment targetSegment){
	List<Output> result = new ArrayList<>();

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case MODEL_CHAIN:
			break;
		default:
			return Collections.emptyList();
	}

	List<Segment> segments = segmentation.getSegments();
	for(Segment segment : segments){
		Model model = segment.getModel();

		if(targetSegment != null && (targetSegment).equals(segment)){
			break;
		}

		Output output = model.getOutput();
		if(output != null){
			result.add(output);
		}
	}

	return result;
}
 
开发者ID:jpmml,项目名称:jpmml-model,代码行数:29,代码来源:FieldResolver.java

示例9: MiningModelEvaluator

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
public MiningModelEvaluator(PMML pmml, MiningModel miningModel){
	super(pmml, miningModel);

	if(miningModel.hasEmbeddedModels()){
		List<EmbeddedModel> embeddedModels = miningModel.getEmbeddedModels();

		EmbeddedModel embeddedModel = Iterables.getFirst(embeddedModels, null);

		throw new UnsupportedElementException(embeddedModel);
	}

	Segmentation segmentation = miningModel.getSegmentation();
	if(segmentation == null){
		throw new MissingElementException(miningModel, PMMLElements.MININGMODEL_SEGMENTATION);
	}

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	if(multipleModelMethod == null){
		throw new MissingAttributeException(segmentation, PMMLAttributes.SEGMENTATION_MULTIPLEMODELMETHOD);
	} // End if

	if(!segmentation.hasSegments()){
		throw new MissingElementException(segmentation, PMMLElements.SEGMENTATION_SEGMENTS);
	}

	LocalTransformations localTransformations = segmentation.getLocalTransformations();
	if(localTransformations != null){
		throw new UnsupportedElementException(localTransformations);
	}
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:31,代码来源:MiningModelEvaluator.java

示例10: evaluateRegression

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
private <V extends Number> Map<FieldName, ?> evaluateRegression(ValueFactory<V> valueFactory, MiningModelEvaluationContext context){
	MiningModel miningModel = getModel();

	List<SegmentResult> segmentResults = evaluateSegmentation(context);

	Map<FieldName, ?> predictions = getSegmentationResult(REGRESSION_METHODS, segmentResults);
	if(predictions != null){
		return predictions;
	}

	Segmentation segmentation = miningModel.getSegmentation();

	Value<V> result;

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case AVERAGE:
		case WEIGHTED_AVERAGE:
		case MEDIAN:
		case WEIGHTED_MEDIAN:
		case SUM:
		case WEIGHTED_SUM:
			result = MiningModelUtil.aggregateValues(valueFactory, segmentResults, multipleModelMethod);
			break;
		case MAJORITY_VOTE:
		case WEIGHTED_MAJORITY_VOTE:
		case MAX:
		case SELECT_FIRST:
		case SELECT_ALL:
		case MODEL_CHAIN:
			throw new InvalidAttributeException(segmentation, multipleModelMethod);
		default:
			throw new UnsupportedAttributeException(segmentation, multipleModelMethod);
	}

	return TargetUtil.evaluateRegression(getTargetField(), result);
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:38,代码来源:MiningModelEvaluator.java

示例11: getSegmentationResult

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
private Map<FieldName, ?> getSegmentationResult(Set<Segmentation.MultipleModelMethod> multipleModelMethods, List<SegmentResult> segmentResults){
	MiningModel miningModel = getModel();

	Segmentation segmentation = miningModel.getSegmentation();

	Segmentation.MultipleModelMethod multipleModelMethod = segmentation.getMultipleModelMethod();
	switch(multipleModelMethod){
		case SELECT_ALL:
			return selectAll(segmentResults);
		case SELECT_FIRST:
			if(segmentResults.size() > 0){
				return segmentResults.get(0);
			}
			break;
		case MODEL_CHAIN:
			if(segmentResults.size() > 0){
				return segmentResults.get(segmentResults.size() - 1);
			}
			break;
		default:
			if(!(multipleModelMethods).contains(multipleModelMethod)){
				throw new UnsupportedAttributeException(segmentation, multipleModelMethod);
			}
			break;
	}

	// "If no segments have predicates that evaluate to true, then the result is a missing value"
	if(segmentResults.size() == 0){
		return Collections.singletonMap(getTargetFieldName(), null);
	}

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

示例12: aggregateVotes

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
static
public <V extends Number> ValueMap<String, V> aggregateVotes(final ValueFactory<V> valueFactory, List<SegmentResult> segmentResults, Segmentation.MultipleModelMethod multipleModelMethod){
	VoteAggregator<String, V> aggregator = new VoteAggregator<String, V>(){

		@Override
		public ValueFactory<V> getValueFactory(){
			return valueFactory;
		}
	};

	for(SegmentResult segmentResult : segmentResults){
		String key;

		try {
			Object targetValue = EvaluatorUtil.decode(segmentResult.getTargetValue());

			key = (String)TypeUtil.cast(DataType.STRING, targetValue);
		} catch(TypeCheckException tce){
			throw tce.ensureContext(segmentResult.getSegment());
		}

		switch(multipleModelMethod){
			case MAJORITY_VOTE:
				aggregator.add(key);
				break;
			case WEIGHTED_MAJORITY_VOTE:
				double weight = segmentResult.getWeight();

				aggregator.add(key, weight);
				break;
			default:
				throw new IllegalArgumentException();
		}
	}

	return aggregator.sumMap();
}
 
开发者ID:jpmml,项目名称:jpmml-evaluator,代码行数:38,代码来源:MiningModelUtil.java

示例13: rdfModelToPMML

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
private PMML rdfModelToPMML(RandomForestModel rfModel,
                            CategoricalValueEncodings categoricalValueEncodings,
                            int maxDepth,
                            int maxSplitCandidates,
                            String impurity,
                            List<Map<Integer,Long>> nodeIDCounts,
                            Map<Integer,Long> predictorIndexCounts) {

  boolean classificationTask = rfModel.algo().equals(Algo.Classification());
  Preconditions.checkState(classificationTask == inputSchema.isClassification());

  DecisionTreeModel[] trees = rfModel.trees();

  Model model;
  if (trees.length == 1) {
    model = toTreeModel(trees[0], categoricalValueEncodings, nodeIDCounts.get(0));
  } else {
    MiningModel miningModel = new MiningModel();
    model = miningModel;
    Segmentation.MultipleModelMethod multipleModelMethodType = classificationTask ?
        Segmentation.MultipleModelMethod.WEIGHTED_MAJORITY_VOTE :
        Segmentation.MultipleModelMethod.WEIGHTED_AVERAGE;
    List<Segment> segments = new ArrayList<>(trees.length);
    for (int treeID = 0; treeID < trees.length; treeID++) {
      TreeModel treeModel =
          toTreeModel(trees[treeID], categoricalValueEncodings, nodeIDCounts.get(treeID));
      segments.add(new Segment()
           .setId(Integer.toString(treeID))
           .setPredicate(new True())
           .setModel(treeModel)
           .setWeight(1.0)); // No weights in MLlib impl now
    }
    miningModel.setSegmentation(new Segmentation(multipleModelMethodType, segments));
  }

  model.setMiningFunction(classificationTask ?
                          MiningFunction.CLASSIFICATION :
                          MiningFunction.REGRESSION);

  double[] importances = countsToImportances(predictorIndexCounts);
  model.setMiningSchema(AppPMMLUtils.buildMiningSchema(inputSchema, importances));
  DataDictionary dictionary =
      AppPMMLUtils.buildDataDictionary(inputSchema, categoricalValueEncodings);

  PMML pmml = PMMLUtils.buildSkeletonPMML();
  pmml.setDataDictionary(dictionary);
  pmml.addModels(model);

  AppPMMLUtils.addExtension(pmml, "maxDepth", maxDepth);
  AppPMMLUtils.addExtension(pmml, "maxSplitCandidates", maxSplitCandidates);
  AppPMMLUtils.addExtension(pmml, "impurity", impurity);

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

示例14: encodeBagging

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
static
public <E extends Estimator> MiningModel encodeBagging(List<E> estimators, List<List<Integer>> estimatorsFeatures, Segmentation.MultipleModelMethod multipleModelMethod, MiningFunction miningFunction, Schema schema){
	Schema segmentSchema = schema.toAnonymousSchema();

	List<Model> models = new ArrayList<>();

	for(int i = 0; i < estimators.size(); i++){
		E estimator = estimators.get(i);
		List<Integer> estimatorFeatures = estimatorsFeatures.get(i);

		Schema estimatorSchema = segmentSchema.toSubSchema(Ints.toArray(estimatorFeatures));

		Model model = estimator.encodeModel(estimatorSchema);

		models.add(model);
	}

	MiningModel miningModel = new MiningModel(miningFunction, ModelUtil.createMiningSchema(schema.getLabel()))
		.setSegmentation(MiningModelUtil.createSegmentation(multipleModelMethod, models));

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

示例15: encodeModel

import org.dmg.pmml.mining.Segmentation; //导入方法依赖的package包/类
@Override
public Model encodeModel(Schema schema){
	List<? extends Classifier> estimators = getEstimators();
	List<? extends Number> weights = getWeights();

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

	List<Model> models = new ArrayList<>();

	for(Classifier estimator : estimators){
		Model model = estimator.encodeModel(schema);

		models.add(model);
	}

	String voting = getVoting();

	Segmentation.MultipleModelMethod multipleModelMethod = parseVoting(voting, (weights != null && weights.size() > 0));

	MiningModel miningModel = new MiningModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel))
		.setSegmentation(MiningModelUtil.createSegmentation(multipleModelMethod, models, weights))
		.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel));

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


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