org.jpmml.converter.LabelUtil Java Examples
The following examples show how to use
org.jpmml.converter.LabelUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Classification.java From jpmml-lightgbm with GNU Affero General Public License v3.0 | 6 votes |
@Override public Label encodeLabel(FieldName targetField, List<?> targetCategories, PMMLEncoder encoder){ DataField dataField; if(targetCategories == null){ targetCategories = LabelUtil.createTargetCategories(this.num_class_); dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.INTEGER, targetCategories); } else { if(targetCategories.size() != this.num_class_){ throw new IllegalArgumentException("Expected " + this.num_class_ + " target categories, got " + targetCategories.size() + " target categories"); } dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.STRING, targetCategories); } return new CategoricalLabel(dataField); }
Example #2
Source File: Classification.java From jpmml-xgboost with GNU Affero General Public License v3.0 | 6 votes |
@Override public Label encodeLabel(FieldName targetField, List<?> targetCategories, PMMLEncoder encoder){ DataField dataField; if(targetCategories == null){ targetCategories = LabelUtil.createTargetCategories(this.num_class); dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.INTEGER, targetCategories); } else { if(targetCategories.size() != this.num_class){ throw new IllegalArgumentException("Expected " + this.num_class + " target categories, got " + targetCategories.size() + " target categories"); } dataField = encoder.createDataField(targetField, OpType.CATEGORICAL, DataType.STRING, targetCategories); } return new CategoricalLabel(dataField); }
Example #3
Source File: ClusteringModelConverter.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 4 votes |
@Override public List<OutputField> registerOutputFields(Label label, org.dmg.pmml.Model pmmlModel, SparkMLEncoder encoder){ T model = getTransformer(); List<Integer> clusters = LabelUtil.createTargetCategories(getNumberOfClusters()); String predictionCol = model.getPredictionCol(); OutputField pmmlPredictedOutputField = ModelUtil.createPredictedField(FieldName.create("pmml(" + predictionCol + ")"), OpType.CATEGORICAL, DataType.STRING) .setFinalResult(false); DerivedOutputField pmmlPredictedField = encoder.createDerivedField(pmmlModel, pmmlPredictedOutputField, true); OutputField predictedOutputField = new OutputField(FieldName.create(predictionCol), OpType.CATEGORICAL, DataType.INTEGER) .setResultFeature(ResultFeature.TRANSFORMED_VALUE) .setExpression(new FieldRef(pmmlPredictedField.getName())); DerivedOutputField predictedField = encoder.createDerivedField(pmmlModel, predictedOutputField, true); encoder.putOnlyFeature(predictionCol, new IndexFeature(encoder, predictedField, clusters)); return Collections.emptyList(); }
Example #4
Source File: ClassificationModelConverter.java From jpmml-sparkml with GNU Affero General Public License v3.0 | 2 votes |
@Override public List<OutputField> registerOutputFields(Label label, Model pmmlModel, SparkMLEncoder encoder){ T model = getTransformer(); CategoricalLabel categoricalLabel = (CategoricalLabel)label; List<Integer> categories = LabelUtil.createTargetCategories(categoricalLabel.size()); String predictionCol = model.getPredictionCol(); Boolean keepPredictionCol = (Boolean)getOption(HasPredictionModelOptions.OPTION_KEEP_PREDICTIONCOL, Boolean.TRUE); OutputField pmmlPredictedOutputField = ModelUtil.createPredictedField(FieldName.create("pmml(" + predictionCol + ")"), OpType.CATEGORICAL, categoricalLabel.getDataType()) .setFinalResult(false); DerivedOutputField pmmlPredictedField = encoder.createDerivedField(pmmlModel, pmmlPredictedOutputField, keepPredictionCol); MapValues mapValues = PMMLUtil.createMapValues(pmmlPredictedField.getName(), categoricalLabel.getValues(), categories) .setDataType(DataType.DOUBLE); OutputField predictedOutputField = new OutputField(FieldName.create(predictionCol), OpType.CONTINUOUS, DataType.DOUBLE) .setResultFeature(ResultFeature.TRANSFORMED_VALUE) .setExpression(mapValues); DerivedOutputField predictedField = encoder.createDerivedField(pmmlModel, predictedOutputField, keepPredictionCol); encoder.putOnlyFeature(predictionCol, new IndexFeature(encoder, predictedField, categories)); List<OutputField> result = new ArrayList<>(); if(model instanceof HasProbabilityCol){ HasProbabilityCol hasProbabilityCol = (HasProbabilityCol)model; String probabilityCol = hasProbabilityCol.getProbabilityCol(); List<Feature> features = new ArrayList<>(); for(int i = 0; i < categoricalLabel.size(); i++){ Object value = categoricalLabel.getValue(i); OutputField probabilityField = ModelUtil.createProbabilityField(FieldName.create(probabilityCol + "(" + value + ")"), DataType.DOUBLE, value); result.add(probabilityField); features.add(new ContinuousFeature(encoder, probabilityField)); } // XXX encoder.putFeatures(probabilityCol, features); } return result; }