Java Code Examples for org.jpmml.converter.Feature#getName()

The following examples show how to use org.jpmml.converter.Feature#getName() . 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: SparkMLEncoder.java    From jpmml-sparkml with GNU Affero General Public License v3.0 6 votes vote down vote up
public void putFeatures(String column, List<Feature> features){
	List<Feature> existingFeatures = this.columnFeatures.get(column);

	if(existingFeatures != null && existingFeatures.size() > 0){

		if(features.size() != existingFeatures.size()){
			throw new IllegalArgumentException("Expected " + existingFeatures.size() + " feature(s), got " + features.size() + " feature(s)");
		}

		for(int i = 0; i < existingFeatures.size(); i++){
			Feature existingFeature = existingFeatures.get(i);
			Feature feature = features.get(i);

			if(!(feature.getName()).equals(existingFeature.getName())){
				throw new IllegalArgumentException("Expected feature column '" + existingFeature.getName() + "', got feature column '" + feature.getName() + "'");
			}
		}
	}

	this.columnFeatures.put(column, features);
}
 
Example 2
Source File: MultiLookupTransformer.java    From jpmml-sklearn with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected List<String> formatColumns(List<Feature> features){
	List<String> result = new ArrayList<>();

	for(Feature feature : features){
		FieldName name = feature.getName();

		result.add("data:" + XMLUtil.createTagName(name.getValue()));
	}

	if(result.contains("data:output")){
		throw new IllegalArgumentException();
	}

	result.add("data:output");

	return result;
}
 
Example 3
Source File: SkLearnEncoder.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
public void renameFeature(Feature feature, FieldName renamedName){
	FieldName name = feature.getName();

	org.dmg.pmml.Field<?> pmmlField = getField(name);

	if(pmmlField instanceof DataField){
		throw new IllegalArgumentException("User input field " + name.getValue() + " cannot be renamed");
	}

	DerivedField derivedField = removeDerivedField(name);

	try {
		Field field = Feature.class.getDeclaredField("name");

		if(!field.isAccessible()){
			field.setAccessible(true);
		}

		field.set(feature, renamedName);
	} catch(ReflectiveOperationException roe){
		throw new RuntimeException(roe);
	}

	derivedField.setName(renamedName);

	addDerivedField(derivedField);
}
 
Example 4
Source File: Domain.java    From jpmml-sklearn with GNU Affero General Public License v3.0 5 votes vote down vote up
static
protected WildcardFeature asWildcardFeature(Feature feature){

	if(feature instanceof WildcardFeature){
		WildcardFeature wildcardFeature = (WildcardFeature)feature;

		return wildcardFeature;
	}

	throw new IllegalArgumentException("Field " + feature.getName() + " is not decorable");
}
 
Example 5
Source File: Formula.java    From jpmml-r with GNU Affero General Public License v3.0 5 votes vote down vote up
public Double getCoefficient(Feature feature, RDoubleVector coefficients){
	FieldName name = feature.getName();

	if(feature instanceof HasDerivedName){
		BiMap<Feature, FieldName> inverseFeatures = this.features.inverse();

		name = inverseFeatures.get(feature);
	}

	return coefficients.getElement(name.getValue());
}
 
Example 6
Source File: RegressionTree.java    From pyramid with Apache License 2.0 5 votes vote down vote up
static
private Predicate encodePredicate(Feature feature, Node node, boolean left){
    FieldName name = feature.getName();
    SimplePredicate.Operator operator;
    String value;

    if(feature instanceof BinaryFeature){
        BinaryFeature binaryFeature = (BinaryFeature)feature;

        operator = (left ? SimplePredicate.Operator.NOT_EQUAL : SimplePredicate.Operator.EQUAL);
        value = binaryFeature.getValue();
    } else

    {
        ContinuousFeature continuousFeature = feature.toContinuousFeature();

        Number splitValue = node.getThreshold();

        DataType dataType = continuousFeature.getDataType();
        switch(dataType){
            case INTEGER:
                splitValue = (int)(splitValue.floatValue() + 1f);
                break;
            case FLOAT:
                break;
            default:
                throw new IllegalArgumentException();
        }

        operator = (left ? SimplePredicate.Operator.LESS_OR_EQUAL : SimplePredicate.Operator.GREATER_THAN);
        value = ValueUtil.formatValue(splitValue);
    }

    SimplePredicate simplePredicate = new SimplePredicate(name, operator)
            .setValue(value);

    return simplePredicate;
}
 
Example 7
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 8
Source File: BaseEstimator.java    From jpmml-sklearn with GNU Affero General Public License v3.0 2 votes vote down vote up
@Override
public Model encodeModel(Schema schema){
	MojoModel mojoModel = getMojoModel();

	Converter<?> converter;

	try {
		ConverterFactory converterFactory = ConverterFactory.newConverterFactory();

		converter = converterFactory.newConverter(mojoModel);
	} catch(Exception e){
		throw new IllegalArgumentException(e);
	}

	Label label = schema.getLabel();
	List<? extends Feature> features = schema.getFeatures();

	H2OEncoder encoder = new H2OEncoder();

	Schema h2oSchema = converter.encodeSchema(encoder);

	Label h2oLabel = h2oSchema.getLabel();
	List<? extends Feature> h2oFeatures = h2oSchema.getFeatures();

	List<Feature> sortedFeatures = new ArrayList<>();

	for(Feature h2oFeature : h2oFeatures){
		FieldName name = h2oFeature.getName();

		Feature feature;

		if(features instanceof FeatureList){
			FeatureList namedFeatures = (FeatureList)features;

			feature = namedFeatures.getFeature(name.getValue());
		} else

		{
			int index = Integer.parseInt((name.getValue()).substring(1)) - 1;

			feature = features.get(index);
		}

		sortedFeatures.add(feature);
	}

	Schema mojoModelSchema = converter.toMojoModelSchema(new Schema(label, sortedFeatures));

	return converter.encodeModel(mojoModelSchema);
}