use of org.apache.spark.ml.feature.Interaction in project jpmml-sparkml by jpmml.
the class InteractionConverter method encodeFeatures.
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder) {
Interaction transformer = getTransformer();
String name = "";
List<Feature> result = new ArrayList<>();
String[] inputCols = transformer.getInputCols();
for (int i = 0; i < inputCols.length; i++) {
String inputCol = inputCols[i];
List<Feature> features = encoder.getFeatures(inputCol);
if (i == 0) {
name = inputCol;
result = features;
} else {
name += (":" + inputCol);
List<Feature> interactionFeatures = new ArrayList<>();
int index = 0;
for (Feature left : result) {
for (Feature right : features) {
interactionFeatures.add(new InteractionFeature(encoder, FieldName.create(name + "[" + index + "]"), DataType.DOUBLE, Arrays.asList(left, right)));
index++;
}
}
result = interactionFeatures;
}
}
return result;
}
Aggregations