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


Java CategoricalLabel类代码示例

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


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


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