Java Code Examples for org.jpmml.converter.Feature#ref()
The following examples show how to use
org.jpmml.converter.Feature#ref() .
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: ImputerUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 6 votes |
static public Feature encodeIndicatorFeature(Feature feature, Object missingValue, SkLearnEncoder encoder){ Expression expression = feature.ref(); if(missingValue != null){ expression = PMMLUtil.createApply(PMMLFunctions.EQUAL, expression, PMMLUtil.createConstant(missingValue, feature.getDataType())); } else { expression = PMMLUtil.createApply(PMMLFunctions.ISMISSING, expression); } DerivedField derivedField = encoder.createDerivedField(FeatureUtil.createName("missing_indicator", feature), OpType.CATEGORICAL, DataType.BOOLEAN, expression); return new BooleanFeature(encoder, derivedField); }
Example 2
Source File: StringNormalizer.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 5 votes |
@Override public List<Feature> encodeFeatures(List<Feature> features, SkLearnEncoder encoder){ String function = getFunction(); Boolean trimBlanks = getTrimBlanks(); if(function == null && !trimBlanks){ return features; } List<Feature> result = new ArrayList<>(); for(Feature feature : features){ Expression expression = feature.ref(); if(function != null){ expression = PMMLUtil.createApply(translateFunction(function), expression); } // End if if(trimBlanks){ expression = PMMLUtil.createApply(PMMLFunctions.TRIMBLANKS, expression); } Field<?> field = encoder.toCategorical(feature.getName(), Collections.emptyList()); // XXX: Should have been set by the previous transformer field.setDataType(DataType.STRING); DerivedField derivedField = encoder.createDerivedField(FeatureUtil.createName("normalize", feature), OpType.CATEGORICAL, DataType.STRING, expression); feature = new StringFeature(encoder, derivedField); result.add(feature); } return result; }
Example 3
Source File: ImputerUtil.java From jpmml-sklearn with GNU Affero General Public License v3.0 | 4 votes |
static public Feature encodeFeature(Feature feature, Boolean addIndicator, Object missingValue, Object replacementValue, MissingValueTreatmentMethod missingValueTreatmentMethod, SkLearnEncoder encoder){ Field<?> field = feature.getField(); if(field instanceof DataField && !addIndicator){ DataField dataField = (DataField)field; encoder.addDecorator(dataField, new MissingValueDecorator(missingValueTreatmentMethod, replacementValue)); if(missingValue != null){ PMMLUtil.addValues(dataField, Collections.singletonList(missingValue), Value.Property.MISSING); } return feature; } // End if if((field instanceof DataField) || (field instanceof DerivedField)){ Expression expression = feature.ref(); if(missingValue != null){ expression = PMMLUtil.createApply(PMMLFunctions.EQUAL, expression, PMMLUtil.createConstant(missingValue, feature.getDataType())); } else { expression = PMMLUtil.createApply(PMMLFunctions.ISMISSING, expression); } expression = PMMLUtil.createApply(PMMLFunctions.IF) .addExpressions(expression) .addExpressions(PMMLUtil.createConstant(replacementValue, feature.getDataType()), feature.ref()); DerivedField derivedField = encoder.createDerivedField(FeatureUtil.createName("imputer", feature), field.getOpType(), field.getDataType(), expression); DataType dataType = derivedField.getDataType(); switch(dataType){ case INTEGER: case FLOAT: case DOUBLE: return new ContinuousFeature(encoder, derivedField); case STRING: return new StringFeature(encoder, derivedField); default: return new ObjectFeature(encoder, derivedField.getName(), derivedField.getDataType()); } } else { throw new IllegalArgumentException(); } }