use of org.apache.spark.ml.feature.MaxAbsScalerModel in project jpmml-sparkml by jpmml.
the class MaxAbsScalerModelConverter method encodeFeatures.
@Override
public List<Feature> encodeFeatures(SparkMLEncoder encoder) {
MaxAbsScalerModel transformer = getTransformer();
List<Feature> features = encoder.getFeatures(transformer.getInputCol());
Vector maxAbs = transformer.maxAbs();
if (maxAbs.size() != features.size()) {
throw new IllegalArgumentException();
}
List<Feature> result = new ArrayList<>();
for (int i = 0; i < features.size(); i++) {
Feature feature = features.get(i);
double maxAbsUnzero = maxAbs.apply(i);
if (maxAbsUnzero == 0d) {
maxAbsUnzero = 1d;
}
if (!ValueUtil.isOne(maxAbsUnzero)) {
ContinuousFeature continuousFeature = feature.toContinuousFeature();
Expression expression = PMMLUtil.createApply("/", continuousFeature.ref(), PMMLUtil.createConstant(maxAbsUnzero));
DerivedField derivedField = encoder.createDerivedField(formatName(transformer, i), OpType.CONTINUOUS, DataType.DOUBLE, expression);
feature = new ContinuousFeature(encoder, derivedField);
}
result.add(feature);
}
return result;
}
Aggregations