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);
}
}
}
}
Aggregations