Java Code Examples for org.dmg.pmml.MissingValueTreatmentMethod#AS_VALUE

The following examples show how to use org.dmg.pmml.MissingValueTreatmentMethod#AS_VALUE . 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: SimpleImputer.java    From jpmml-sklearn with GNU Affero General Public License v3.0 6 votes vote down vote up
static
private MissingValueTreatmentMethod parseStrategy(String strategy){

	switch(strategy){
		case "constant":
			return MissingValueTreatmentMethod.AS_VALUE;
		case "mean":
			return MissingValueTreatmentMethod.AS_MEAN;
		case "median":
			return MissingValueTreatmentMethod.AS_MEDIAN;
		case "most_frequent":
			return MissingValueTreatmentMethod.AS_MODE;
		default:
			throw new IllegalArgumentException(strategy);
	}
}
 
Example 2
Source File: DomainUtil.java    From jpmml-sklearn with GNU Affero General Public License v3.0 6 votes vote down vote up
static
public MissingValueTreatmentMethod parseMissingValueTreatment(String missingValueTreatment){

	if(missingValueTreatment == null){
		return null;
	}

	switch(missingValueTreatment){
		case "as_is":
			return MissingValueTreatmentMethod.AS_IS;
		case "as_mean":
			return MissingValueTreatmentMethod.AS_MEAN;
		case "as_mode":
			return MissingValueTreatmentMethod.AS_MODE;
		case "as_median":
			return MissingValueTreatmentMethod.AS_MEDIAN;
		case "as_value":
			return MissingValueTreatmentMethod.AS_VALUE;
		case "return_invalid":
			return MissingValueTreatmentMethod.RETURN_INVALID;
		default:
			throw new IllegalArgumentException(missingValueTreatment);
	}
}
 
Example 3
Source File: Domain.java    From jpmml-sklearn with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){
	MissingValueTreatmentMethod missingValueTreatment = DomainUtil.parseMissingValueTreatment(getMissingValueTreatment());
	Object missingValueReplacement = getMissingValueReplacement();
	List<?> missingValues = getMissingValues();

	if(missingValueReplacement != null){

		if(missingValueTreatment == null){
			missingValueTreatment = MissingValueTreatmentMethod.AS_VALUE;
		}
	}

	InvalidValueTreatmentMethod invalidValueTreatment = DomainUtil.parseInvalidValueTreatment(getInvalidValueTreatment());
	Object invalidValueReplacement = getInvalidValueReplacement();

	if(invalidValueReplacement != null){

		if(invalidValueTreatment == null){
			invalidValueTreatment = InvalidValueTreatmentMethod.AS_IS;
		}
	}

	for(Feature feature : features){
		WildcardFeature wildcardFeature = asWildcardFeature(feature);

		DataField dataField = wildcardFeature.getField();

		DataType dataType = dataField.getDataType();

		if(missingValueTreatment != null){
			Object pmmlMissingValueReplacement = (missingValueReplacement != null ? standardizeValue(dataType, missingValueReplacement) : null);

			encoder.addDecorator(dataField, new MissingValueDecorator(missingValueTreatment, pmmlMissingValueReplacement));
		} // End if

		if(missingValues != null){
			PMMLUtil.addValues(dataField, standardizeValues(dataType, missingValues), Value.Property.MISSING);
		} // End if

		if(invalidValueTreatment != null){
			Object pmmlInvalidValueReplacement = (invalidValueReplacement != null ? standardizeValue(dataType, invalidValueReplacement) : null);

			encoder.addDecorator(dataField, new InvalidValueDecorator(invalidValueTreatment, pmmlInvalidValueReplacement));
		}
	}

	return features;
}