本文整理汇总了Java中org.jpmml.converter.CategoricalLabel.size方法的典型用法代码示例。如果您正苦于以下问题:Java CategoricalLabel.size方法的具体用法?Java CategoricalLabel.size怎么用?Java CategoricalLabel.size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jpmml.converter.CategoricalLabel
的用法示例。
在下文中一共展示了CategoricalLabel.size方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: 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);
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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)");
}
}
示例7: 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;
}
示例8: 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);
}
示例9: 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();
}
}
示例10: encodeModel
import org.jpmml.converter.CategoricalLabel; //导入方法依赖的package包/类
@Override
public Model encodeModel(Schema schema){
RGenericVector glm = getObject();
RDoubleVector coefficients = (RDoubleVector)glm.getValue("coefficients");
RGenericVector family = (RGenericVector)glm.getValue("family");
Double intercept = coefficients.getValue(getInterceptName(), true);
RStringVector familyFamily = (RStringVector)family.getValue("family");
RStringVector familyLink = (RStringVector)family.getValue("link");
Label label = schema.getLabel();
List<Feature> features = schema.getFeatures();
if(coefficients.size() != (features.size() + (intercept != null ? 1 : 0))){
throw new IllegalArgumentException();
}
List<Double> featureCoefficients = getFeatureCoefficients(features, coefficients);
MiningFunction miningFunction = getMiningFunction(familyFamily.asScalar());
String targetCategory = null;
switch(miningFunction){
case CLASSIFICATION:
{
CategoricalLabel categoricalLabel = (CategoricalLabel)label;
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(label), null, null, null)
.setDistribution(parseFamily(familyFamily.asScalar()))
.setLinkFunction(parseLinkFunction(familyLink.asScalar()))
.setLinkParameter(parseLinkParameter(familyLink.asScalar()));
GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, features, intercept, featureCoefficients, targetCategory);
switch(miningFunction){
case CLASSIFICATION:
generalRegressionModel.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, (CategoricalLabel)label));
break;
default:
break;
}
return generalRegressionModel;
}
示例11: encodeMultinomialClassification
import org.jpmml.converter.CategoricalLabel; //导入方法依赖的package包/类
private MiningModel encodeMultinomialClassification(List<TreeModel> treeModels, Double initF, Schema schema){
CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();
Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.DOUBLE), schema.getFeatures());
List<Model> miningModels = new ArrayList<>();
for(int i = 0, columns = categoricalLabel.size(), rows = (treeModels.size() / columns); i < columns; i++){
MiningModel miningModel = createMiningModel(CMatrixUtil.getColumn(treeModels, rows, columns, i), initF, segmentSchema)
.setOutput(ModelUtil.createPredictedOutput(FieldName.create("gbmValue(" + categoricalLabel.getValue(i) + ")"), OpType.CONTINUOUS, DataType.DOUBLE));
miningModels.add(miningModel);
}
return MiningModelUtil.createClassification(miningModels, RegressionModel.NormalizationMethod.SOFTMAX, true, schema);
}
示例12: 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();
// modified here
if(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 = 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);
}
示例13: encodeModel
import org.jpmml.converter.CategoricalLabel; //导入方法依赖的package包/类
@Override
public Model encodeModel(Schema schema){
RGenericVector lrm = getObject();
RDoubleVector coefficients = (RDoubleVector)lrm.getValue("coefficients");
CategoricalLabel categoricalLabel = (CategoricalLabel)schema.getLabel();
if(categoricalLabel.size() != 2){
throw new IllegalArgumentException();
}
String targetCategory = categoricalLabel.getValue(1);
Double intercept = coefficients.getValue(getInterceptName(), true);
List<Feature> features = schema.getFeatures();
if(coefficients.size() != (features.size() + (intercept != null ? 1 : 0))){
throw new IllegalArgumentException();
}
List<Double> featureCoefficients = getFeatureCoefficients(features, coefficients);
GeneralRegressionModel generalRegressionModel = new GeneralRegressionModel(GeneralRegressionModel.ModelType.GENERALIZED_LINEAR, MiningFunction.CLASSIFICATION, ModelUtil.createMiningSchema(categoricalLabel), null, null, null)
.setLinkFunction(GeneralRegressionModel.LinkFunction.LOGIT)
.setOutput(ModelUtil.createProbabilityOutput(DataType.DOUBLE, categoricalLabel));
GeneralRegressionModelUtil.encodeRegressionTable(generalRegressionModel, features, intercept, featureCoefficients, targetCategory);
return generalRegressionModel;
}