org.jpmml.converter.PMMLEncoder Java Examples

The following examples show how to use org.jpmml.converter.PMMLEncoder. 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 vote down vote up
@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 vote down vote up
@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: TermFeature.java    From jpmml-sparkml with GNU Affero General Public License v3.0 5 votes vote down vote up
public TermFeature(PMMLEncoder encoder, DefineFunction defineFunction, Feature feature, String value){
	super(encoder, FieldName.create(defineFunction.getName() + "(" + value + ")"), defineFunction.getDataType());

	setDefineFunction(defineFunction);

	setFeature(feature);
	setValue(value);
}
 
Example #4
Source File: CategoricalDomain.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Feature encode(WildcardFeature wildcardFeature, List<?> values){
	PMMLEncoder encoder = wildcardFeature.getEncoder();

	if(values == null || values.isEmpty()){
		DataField dataField = (DataField)encoder.getField(wildcardFeature.getName());

		dataField.setOpType(OpType.CATEGORICAL);

		return new ObjectFeature(encoder, dataField.getName(), dataField.getDataType());
	}

	return wildcardFeature.toCategoricalFeature(standardizeValues(wildcardFeature.getDataType(), values));
}
 
Example #5
Source File: StackingUtil.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
static
public PMMLEncoder getEncoder(List<? extends Feature> features){
	Set<PMMLEncoder> encoders = features.stream()
		.map(feature -> feature.getEncoder())
		.collect(Collectors.toSet());

	return Iterables.getOnlyElement(encoders);
}
 
Example #6
Source File: Regression.java    From jpmml-xgboost with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Label encodeLabel(FieldName targetField, List<?> targetCategories, PMMLEncoder encoder){

	if(targetCategories != null){
		throw new IllegalArgumentException("Regression requires zero target categories");
	}

	DataField dataField = encoder.createDataField(targetField, OpType.CONTINUOUS, DataType.FLOAT);

	return new ContinuousLabel(dataField);
}
 
Example #7
Source File: OneHotEncoderModelConverter.java    From jpmml-sparkml with GNU Affero General Public License v3.0 5 votes vote down vote up
static
public List<BinaryFeature> encodeFeature(PMMLEncoder encoder, Feature feature, List<?> values, boolean dropLast){
	List<BinaryFeature> result = new ArrayList<>();

	if(dropLast){
		values = values.subList(0, values.size() - 1);
	}

	for(Object value : values){
		result.add(new BinaryFeature(encoder, feature, value));
	}

	return result;
}
 
Example #8
Source File: Regression.java    From jpmml-lightgbm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Label encodeLabel(FieldName targetField, List<?> targetCategories, PMMLEncoder encoder){

	if(targetCategories != null && targetCategories.size() > 0){
		throw new IllegalArgumentException("Regression requires zero target categories");
	}

	DataField dataField = encoder.createDataField(targetField, OpType.CONTINUOUS, DataType.DOUBLE);

	return new ContinuousLabel(dataField);
}
 
Example #9
Source File: RegressionTableUtil.java    From jpmml-sparkml with GNU Affero General Public License v3.0 4 votes vote down vote up
static
private MapValues createMapValues(FieldName name, Object identifier, List<Feature> features, List<Double> coefficients){
	ListIterator<Feature> featureIt = features.listIterator();
	ListIterator<Double> coefficientIt = coefficients.listIterator();

	PMMLEncoder encoder = null;

	List<Object> inputValues = new ArrayList<>();
	List<Double> outputValues = new ArrayList<>();

	while(featureIt.hasNext()){
		Feature feature = featureIt.next();
		Double coefficient = coefficientIt.next();

		if(!(feature instanceof BinaryFeature)){
			continue;
		}

		BinaryFeature binaryFeature = (BinaryFeature)feature;
		if(!(name).equals(binaryFeature.getName())){
			continue;
		}

		featureIt.remove();
		coefficientIt.remove();

		if(encoder == null){
			encoder = binaryFeature.getEncoder();
		}

		inputValues.add(binaryFeature.getValue());
		outputValues.add(coefficient);
	}

	MapValues mapValues = PMMLUtil.createMapValues(name, inputValues, outputValues)
		.setDefaultValue(0d)
		.setDataType(DataType.DOUBLE);

	DerivedField derivedField = encoder.createDerivedField(FieldName.create("lookup(" + name.getValue() + (identifier != null ? (", " + identifier) : "") + ")"), OpType.CONTINUOUS, DataType.DOUBLE, mapValues);

	featureIt.add(new ContinuousFeature(encoder, derivedField));
	coefficientIt.add(1d);

	return mapValues;
}
 
Example #10
Source File: WeightedTermFeature.java    From jpmml-sparkml with GNU Affero General Public License v3.0 4 votes vote down vote up
public WeightedTermFeature(PMMLEncoder encoder, DefineFunction defineFunction, Feature feature, String value, Number weight){
	super(encoder, defineFunction, feature, value);

	setWeight(weight);
}
 
Example #11
Source File: BinarizedCategoricalFeature.java    From jpmml-sparkml with GNU Affero General Public License v3.0 4 votes vote down vote up
public BinarizedCategoricalFeature(PMMLEncoder encoder, FieldName name, DataType dataType, List<BinaryFeature> binaryFeatures){
	super(encoder, name, dataType);

	setBinaryFeatures(binaryFeatures);
}
 
Example #12
Source File: DirectCategoricalFeature.java    From jpmml-lightgbm with GNU Affero General Public License v3.0 4 votes vote down vote up
public DirectCategoricalFeature(PMMLEncoder encoder, DataField dataField){
	super(encoder, dataField);
}
 
Example #13
Source File: ObjFunction.java    From jpmml-xgboost with GNU Affero General Public License v3.0 4 votes vote down vote up
abstract
public Label encodeLabel(FieldName targetField, List<?> targetCategories, PMMLEncoder encoder);
 
Example #14
Source File: BaseNFeature.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
public BaseNFeature(PMMLEncoder encoder, Field<?> field, int base, SetMultimap<Integer, ?> values){
	this(encoder, field.getName(), field.getDataType(), base, values);
}
 
Example #15
Source File: BaseNFeature.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
public BaseNFeature(PMMLEncoder encoder, Feature feature, int base, SetMultimap<Integer, ?> values){
	this(encoder, feature.getName(), feature.getDataType(), base, values);
}
 
Example #16
Source File: BaseNFeature.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
public BaseNFeature(PMMLEncoder encoder, FieldName name, DataType dataType, int base, SetMultimap<Integer, ?> values){
	super(encoder, name, dataType);

	setBase(base);
	setValues(values);
}
 
Example #17
Source File: ObjectiveFunction.java    From jpmml-lightgbm with GNU Affero General Public License v3.0 4 votes vote down vote up
abstract
public Label encodeLabel(FieldName targetField, List<?> targetCategories, PMMLEncoder encoder);
 
Example #18
Source File: BinaryCategoricalFeature.java    From jpmml-lightgbm with GNU Affero General Public License v3.0 4 votes vote down vote up
public BinaryCategoricalFeature(PMMLEncoder encoder, BinaryFeature binaryFeature){
	super(encoder, binaryFeature, Arrays.asList(null, binaryFeature.getValue()));
}