Search in sources :

Example 1 with HasOutputCol

use of org.apache.spark.ml.param.shared.HasOutputCol in project jpmml-sparkml by jpmml.

the class FeatureConverter method registerFeatures.

public void registerFeatures(SparkMLEncoder encoder) {
    Transformer transformer = getTransformer();
    if (transformer instanceof HasOutputCol) {
        HasOutputCol hasOutputCol = (HasOutputCol) transformer;
        String outputCol = hasOutputCol.getOutputCol();
        List<Feature> features = encodeFeatures(encoder);
        encoder.putFeatures(outputCol, features);
    } else if (transformer instanceof HasOutputCols) {
        HasOutputCols hasOutputCols = (HasOutputCols) transformer;
        String[] outputCols = hasOutputCols.getOutputCols();
        List<Feature> features = encodeFeatures(encoder);
        if (outputCols.length != features.size()) {
            throw new IllegalArgumentException("Expected " + outputCols.length + " features, got " + features.size() + " features");
        }
        for (int i = 0; i < outputCols.length; i++) {
            String outputCol = outputCols[i];
            Feature feature = features.get(i);
            if (feature instanceof BinarizedCategoricalFeature) {
                BinarizedCategoricalFeature binarizedCategoricalFeature = (BinarizedCategoricalFeature) feature;
                encoder.putFeatures(outputCol, (List) binarizedCategoricalFeature.getBinaryFeatures());
            } else {
                encoder.putOnlyFeature(outputCol, feature);
            }
        }
    }
}
Also used : Transformer(org.apache.spark.ml.Transformer) List(java.util.List) HasOutputCols(org.apache.spark.ml.param.shared.HasOutputCols) Feature(org.jpmml.converter.Feature) HasOutputCol(org.apache.spark.ml.param.shared.HasOutputCol)

Aggregations

List (java.util.List)1 Transformer (org.apache.spark.ml.Transformer)1 HasOutputCol (org.apache.spark.ml.param.shared.HasOutputCol)1 HasOutputCols (org.apache.spark.ml.param.shared.HasOutputCols)1 Feature (org.jpmml.converter.Feature)1