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

Java CategoricalLabel类代码示例

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

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



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

示例1: encodeMiningModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public MiningModel encodeMiningModel(List<Tree> trees, Integer numIteration, Schema schema){
	Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.DOUBLE), schema.getFeatures());

	List<MiningModel> miningModels = new ArrayList<>();

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

	for(int i = 0, rows = categoricalLabel.size(), columns = (trees.size() / rows); i < rows; i++){
		MiningModel miningModel = createMiningModel(FortranMatrixUtil.getRow(trees, rows, columns, i), numIteration, segmentSchema)
			.setOutput(ModelUtil.createPredictedOutput(FieldName.create("lgbmValue(" + categoricalLabel.getValue(i) + ")"), OpType.CONTINUOUS, DataType.DOUBLE));

		miningModels.add(miningModel);
	}

	return MiningModelUtil.createClassification(miningModels, RegressionModel.NormalizationMethod.SOFTMAX, true, schema);
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:18,代码来源:MultinomialLogisticRegression.java


示例2: registerOutputFields

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder){
	List<OutputField> result = super.registerOutputFields(label, encoder);

	MiningFunction miningFunction = getMiningFunction();
	switch(miningFunction){
		case CLASSIFICATION:
			CategoricalLabel categoricalLabel = (CategoricalLabel)label;

			result = new ArrayList<>(result);
			result.addAll(ModelUtil.createProbabilityFields(DataType.DOUBLE, categoricalLabel.getValues()));
			break;
		default:
			break;
	}

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


示例3: encodeMiningModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public MiningModel encodeMiningModel(List<RegTree> regTrees, float base_score, Integer ntreeLimit, Schema schema){
	Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.FLOAT), schema.getFeatures());

	List<MiningModel> miningModels = new ArrayList<>();

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

	for(int i = 0, columns = categoricalLabel.size(), rows = (regTrees.size() / columns); i < columns; i++){
		MiningModel miningModel = createMiningModel(CMatrixUtil.getColumn(regTrees, rows, columns, i), base_score, ntreeLimit, segmentSchema)
			.setOutput(ModelUtil.createPredictedOutput(FieldName.create("xgbValue(" + categoricalLabel.getValue(i) + ")"), OpType.CONTINUOUS, DataType.FLOAT));

		miningModels.add(miningModel);
	}

	return MiningModelUtil.createClassification(miningModels, RegressionModel.NormalizationMethod.SOFTMAX, true, schema);
}
 
开发者ID:jpmml,项目名称:jpmml-xgboost,代码行数:18,代码来源:MultinomialLogisticRegression.java


示例4: createClassificationNeuralOutputs

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
static
public NeuralOutputs createClassificationNeuralOutputs(List<? extends Entity> entities, CategoricalLabel categoricalLabel){

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

	NeuralOutputs neuralOutputs = new NeuralOutputs();

	for(int i = 0; i < categoricalLabel.size(); i++){
		Entity entity = entities.get(i);

		DerivedField derivedField = new DerivedField(OpType.CATEGORICAL, categoricalLabel.getDataType())
			.setExpression(new NormDiscrete(categoricalLabel.getName(), categoricalLabel.getValue(i)));

		NeuralOutput neuralOutput = new NeuralOutput()
			.setOutputNeuron(entity.getId())
			.setDerivedField(derivedField);

		neuralOutputs.addNeuralOutputs(neuralOutput);
	}

	return neuralOutputs;
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:25,代码来源:NeuralNetworkUtil.java


示例5: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的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


示例6: encodeLabel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public Label encodeLabel(FieldName targetField, List<String> targetCategories, PMMLEncoder encoder){
	targetCategories = prepareTargetCategories(targetCategories);

	DataField dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.STRING, targetCategories);

	return new CategoricalLabel(dataField);
}
 
开发者ID:jpmml,项目名称:jpmml-lightgbm,代码行数:9,代码来源:Classification.java


示例7: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public GeneralRegressionModel encodeModel(Schema schema){
	GeneralizedLinearRegressionModel model = getTransformer();

	String targetCategory = null;

	MiningFunction miningFunction = getMiningFunction();
	switch(miningFunction){
		case CLASSIFICATION:
			CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

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

			targetCategory = categoricalLabel.getValue(1);
			break;
		default:
			break;
	}

	GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, miningFunction, ModelUtil.createMiningSchema(schema.getLabel()), null, null, null)
		.setDistribution(parseFamily(model.getFamily()))
		.setLinkFunction(parseLinkFunction(model.getLink()))
		.setLinkParameter(parseLinkParameter(model.getLink()));

	GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, schema.getFeatures(), model.intercept(), VectorUtil.toList(model.coefficients()), targetCategory);

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


示例8: registerOutputFields

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public List<OutputField> registerOutputFields(Label label, SparkMLEncoder encoder){
	MultilayerPerceptronClassificationModel model = getTransformer();

	List<OutputField> result = super.registerOutputFields(label, encoder);

	if(!(model instanceof HasProbabilityCol)){
		CategoricalLabel categoricalLabel = (CategoricalLabel)label;

		result = new ArrayList<>(result);
		result.addAll(ModelUtil.createProbabilityFields(DataType.DOUBLE, categoricalLabel.getValues()));
	}

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


示例9: createBinaryLogisticClassification

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
static
public RegressionModel createBinaryLogisticClassification(MathContext mathContext, List<? extends Feature> features, List<Double> coefficients, Double intercept, RegressionModel.NormalizationMethod normalizationMethod, boolean hasProbabilityDistribution, Schema schema){
	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	if(categoricalLabel.size() != 2){
		throw new IllegalArgumentException();
	} // End if

	if(normalizationMethod != null){

		switch(normalizationMethod){
			case NONE:
			case LOGIT:
			case PROBIT:
			case CLOGLOG:
			case LOGLOG:
			case CAUCHIT:
				break;
			default:
				throw new IllegalArgumentException();
		}
	}

	RegressionTable activeRegressionTable = RegressionModelUtil.createRegressionTable(features, coefficients, intercept)
		.setTargetCategory(categoricalLabel.getValue(1));

	RegressionTable passiveRegressionTable = RegressionModelUtil.createRegressionTable(Collections.<Feature>emptyList(), Collections.<Double>emptyList(), null)
		.setTargetCategory(categoricalLabel.getValue(0));

	RegressionModel regressionModel = new RegressionModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), null)
		.setNormalizationMethod(normalizationMethod)
		.setMathContext(ModelUtil.simplifyMathContext(mathContext))
		.addRegressionTables(activeRegressionTable, passiveRegressionTable)
		.setOutput(hasProbabilityDistribution ? ModelUtil.createProbabilityOutput(mathContext, categoricalLabel) : null);

	return regressionModel;
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:38,代码来源:RegressionModelUtil.java


示例10: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public MiningModel encodeModel(Schema schema){
	MiningModel miningModel = BaseForestUtil.encodeBaseForest(this, Segmentation.MultipleModelMethod.AVERAGE, MiningFunction.CLASSIFICATION, schema)
		.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, (CategoricalLabel)schema.getLabel()));

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


示例11: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public TreeModel encodeModel(Schema schema){
	TreeModel treeModel = TreeModelUtil.encodeTreeModel(this, MiningFunction.CLASSIFICATION, schema)
		.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, (CategoricalLabel)schema.getLabel()));

	return TreeModelUtil.transform(this, treeModel);
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:8,代码来源:TreeClassifier.java


示例12: checkSize

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
static
public void checkSize(int size, CategoricalLabel categoricalLabel){

	if(categoricalLabel.size() != size){
		throw new IllegalArgumentException("Expected " + size + " class(es), got " + categoricalLabel.size() + " class(es)");
	}
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:8,代码来源:ClassifierUtil.java


示例13: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public NeuralNetwork encodeModel(Schema schema){
	String activation = getActivation();

	List<? extends HasArray> coefs = getCoefs();
	List<? extends HasArray> intercepts = getIntercepts();

	NeuralNetwork neuralNetwork = BaseMultilayerPerceptronUtil.encodeNeuralNetwork(MiningFunction.CLASSIFICATION, activation, coefs, intercepts, schema)
		.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, (CategoricalLabel)schema.getLabel()));

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


示例14: encodeClassificationScore

import org.jpmml.converter.CategoricalLabel; //导入依赖的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


示例15: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public NeuralNetwork encodeModel(TensorFlowEncoder encoder){
	DataField dataField = encoder.createDataField(FieldName.create("_target"), OpType.CATEGORICAL, DataType.INTEGER);

	NeuralNetwork neuralNetwork = encodeNeuralNetwork(encoder);

	List<NeuralLayer> neuralLayers = neuralNetwork.getNeuralLayers();

	NeuralLayer neuralLayer = Iterables.getLast(neuralLayers);

	List<Neuron> neurons = neuralLayer.getNeurons();

	List<String> categories;

	if(neurons.size() == 1){
		neuralLayer.setActivationFunction(NeuralNetwork.ActivationFunction.LOGISTIC);

		Neuron neuron = Iterables.getOnlyElement(neurons);

		neuralLayer = new NeuralLayer()
			.setActivationFunction(NeuralNetwork.ActivationFunction.IDENTITY);

		categories = Arrays.asList("0", "1");

		// p(no event) = 1 - p(event)
		Neuron passiveNeuron = new Neuron()
			.setId(String.valueOf(neuralLayers.size() + 1) + "/" + categories.get(0))
			.setBias(ValueUtil.floatToDouble(1f))
			.addConnections(new Connection(neuron.getId(), -1f));

		// p(event)
		Neuron activeNeuron = new Neuron()
			.setId(String.valueOf(neuralLayers.size() + 1) + "/" + categories.get(1))
			.setBias(null)
			.addConnections(new Connection(neuron.getId(), 1f));

		neuralLayer.addNeurons(passiveNeuron, activeNeuron);

		neuralNetwork.addNeuralLayers(neuralLayer);

		neurons = neuralLayer.getNeurons();
	} else

	if(neurons.size() > 2){
		neuralLayer
			.setActivationFunction(NeuralNetwork.ActivationFunction.IDENTITY)
			.setNormalizationMethod(NeuralNetwork.NormalizationMethod.SOFTMAX);

		categories = new ArrayList<>();

		for(int i = 0; i < neurons.size(); i++){
			String category = String.valueOf(i);

			categories.add(category);
		}
	} else

	{
		throw new IllegalArgumentException();
	}

	dataField = encoder.toCategorical(dataField.getName(), categories);

	CategoricalLabel categoricalLabel = new CategoricalLabel(dataField);

	neuralNetwork
		.setMiningFunction(MiningFunction.CLASSIFICATION)
		.setMiningSchema(ModelUtil.createMiningSchema(categoricalLabel))
		.setNeuralOutputs(NeuralNetworkUtil.createClassificationNeuralOutputs(neurons, categoricalLabel))
		.setOutput(ModelUtil.createProbabilityOutput(DataType.FLOAT, categoricalLabel));

	return neuralNetwork;
}
 
开发者ID:jpmml,项目名称:jpmml-tensorflow,代码行数:74,代码来源:DNNClassifier.java


示例16: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public RegressionModel encodeModel(TensorFlowEncoder encoder){
	DataField dataField = encoder.createDataField(FieldName.create("_target"), OpType.CATEGORICAL, DataType.INTEGER);

	RegressionModel regressionModel = encodeRegressionModel(encoder);

	List<RegressionTable> regressionTables = regressionModel.getRegressionTables();

	List<String> categories;

	if(regressionTables.size() == 1){
		categories = Arrays.asList("0", "1");

		RegressionTable activeRegressionTable = regressionTables.get(0)
			.setTargetCategory(categories.get(1));

		RegressionTable passiveRegressionTable = new RegressionTable(0)
			.setTargetCategory(categories.get(0));

		regressionModel.addRegressionTables(passiveRegressionTable);
	} else

	if(regressionTables.size() > 2){
		categories = new ArrayList<>();

		for(int i = 0; i < regressionTables.size(); i++){
			RegressionTable regressionTable = regressionTables.get(i);
			String category = String.valueOf(i);

			regressionTable.setTargetCategory(category);

			categories.add(category);
		}
	} else

	{
		throw new IllegalArgumentException();
	}

	dataField = encoder.toCategorical(dataField.getName(), categories);

	CategoricalLabel categoricalLabel = new CategoricalLabel(dataField);

	regressionModel
		.setMiningFunction(MiningFunction.CLASSIFICATION)
		.setNormalizationMethod(RegressionModel.NormalizationMethod.SOFTMAX)
		.setMiningSchema(ModelUtil.createMiningSchema(categoricalLabel))
		.setOutput(ModelUtil.createProbabilityOutput(DataType.FLOAT, categoricalLabel));

	return regressionModel;
}
 
开发者ID:jpmml,项目名称:jpmml-tensorflow,代码行数:52,代码来源:LinearClassifier.java


示例17: createClassification

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
static
public MiningModel createClassification(List<? extends Model> models, RegressionModel.NormalizationMethod normalizationMethod, boolean hasProbabilityDistribution, Schema schema){
	CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();

	if(categoricalLabel.size() < 3 || categoricalLabel.size() != models.size()){
		throw new IllegalArgumentException();
	} // End if

	if(normalizationMethod != null){

		switch(normalizationMethod){
			case NONE:
			case SIMPLEMAX:
			case SOFTMAX:
				break;
			default:
				throw new IllegalArgumentException();
		}
	}

	MathContext mathContext = null;

	List<RegressionTable> regressionTables = new ArrayList<>();

	for(int i = 0; i < categoricalLabel.size(); i++){
		Model model = models.get(i);

		MathContext modelMathContext = model.getMathContext();
		if(modelMathContext == null){
			modelMathContext = MathContext.DOUBLE;
		} // End if

		if(mathContext == null){
			mathContext = modelMathContext;
		} else

		{
			if(!Objects.equals(mathContext, modelMathContext)){
				throw new IllegalArgumentException();
			}
		}

		Feature feature = MiningModelUtil.MODEL_PREDICTION.apply(model);

		RegressionTable regressionTable = RegressionModelUtil.createRegressionTable(Collections.singletonList(feature), Collections.singletonList(1d), null)
			.setTargetCategory(categoricalLabel.getValue(i));

		regressionTables.add(regressionTable);
	}

	RegressionModel regressionModel = new RegressionModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), regressionTables)
		.setNormalizationMethod(normalizationMethod)
		.setMathContext(ModelUtil.simplifyMathContext(mathContext))
		.setOutput(hasProbabilityDistribution ? ModelUtil.createProbabilityOutput(mathContext, categoricalLabel) : null);

	List<Model> segmentationModels = new ArrayList<>(models);
	segmentationModels.add(regressionModel);

	return createModelChain(segmentationModels, schema);
}
 
开发者ID:jpmml,项目名称:jpmml-converter,代码行数:61,代码来源:MiningModelUtil.java


示例18: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的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


示例19: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的package包/类
@Override
public RegressionModel encodeModel(Schema schema){
	int[] shape = getCoefShape();

	int numberOfClasses = shape[0];
	int numberOfFeatures = shape[1];

	boolean hasProbabilityDistribution = hasProbabilityDistribution();

	List<? extends Number> coef = getCoef();
	List<? extends Number> intercepts = getIntercept();

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

	List<Feature> features = schema.getFeatures();

	if(numberOfClasses == 1){
		ClassifierUtil.checkSize(2, categoricalLabel);

		return RegressionModelUtil.createBinaryLogisticClassification(features, ValueUtil.asDoubles(CMatrixUtil.getRow(coef, numberOfClasses, numberOfFeatures, 0)), ValueUtil.asDouble(intercepts.get(0)), RegressionModel.NormalizationMethod.LOGIT, hasProbabilityDistribution, schema);
	} else

	if(numberOfClasses >= 3){
		ClassifierUtil.checkSize(numberOfClasses, categoricalLabel);

		List<RegressionTable> regressionTables = new ArrayList<>();

		for(int i = 0, rows = categoricalLabel.size(); i < rows; i++){
			RegressionTable regressionTable = RegressionModelUtil.createRegressionTable(features, ValueUtil.asDoubles(CMatrixUtil.getRow(coef, numberOfClasses, numberOfFeatures, i)), ValueUtil.asDouble(intercepts.get(i)))
				.setTargetCategory(categoricalLabel.getValue(i));

			regressionTables.add(regressionTable);
		}

		RegressionModel regressionModel = new RegressionModel(MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), regressionTables)
			.setNormalizationMethod(RegressionModel.NormalizationMethod.LOGIT)
			.setOutput(hasProbabilityDistribution ? ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel) : null);

		return regressionModel;
	} else

	{
		throw new IllegalArgumentException();
	}
}
 
开发者ID:jpmml,项目名称:jpmml-sklearn,代码行数:46,代码来源:BaseLinearClassifier.java


示例20: encodeModel

import org.jpmml.converter.CategoricalLabel; //导入依赖的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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Cursor类代码示例发布时间:2022-05-23
下一篇:
Java ClusterNode类代码示例发布时间: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