use of org.apache.spark.ml.feature.OneHotEncoder in project jpmml-sparkml by jpmml.
the class OneHotEncoderConverter method encodeFeatures.
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder) {
OneHotEncoder transformer = getTransformer();
boolean dropLast = true;
Option<Object> dropLastOption = transformer.get(transformer.dropLast());
if (dropLastOption.isDefined()) {
dropLast = (Boolean) dropLastOption.get();
}
CategoricalFeature categoricalFeature = (CategoricalFeature) encoder.getOnlyFeature(transformer.getInputCol());
List<String> values = categoricalFeature.getValues();
if (dropLast) {
values = values.subList(0, values.size() - 1);
}
List<Feature> result = new ArrayList<>();
for (String value : values) {
result.add(new BinaryFeature(encoder, categoricalFeature.getName(), DataType.STRING, value));
}
return result;
}
Aggregations