Search in sources :

Example 1 with Interaction

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;
}
Also used : InteractionFeature(org.jpmml.converter.InteractionFeature) Interaction(org.apache.spark.ml.feature.Interaction) ArrayList(java.util.ArrayList) Feature(org.jpmml.converter.Feature) InteractionFeature(org.jpmml.converter.InteractionFeature)

Aggregations

ArrayList (java.util.ArrayList)1 Interaction (org.apache.spark.ml.feature.Interaction)1 Feature (org.jpmml.converter.Feature)1 InteractionFeature (org.jpmml.converter.InteractionFeature)1