Skip to content

Commit 4e1fe87

Browse files
authored
fix: SparkML StandardScaler conversion fails when withStd or withMean is set to true (#555)
Signed-off-by: Jason Wang <[email protected]>
1 parent 0a40d6d commit 4e1fe87

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

onnxmltools/convert/sparkml/operator_converters/scaler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def convert_sparkml_scaler(scope, operator, container):
1818
attrs = {'name': scope.get_unique_operator_name(op_type)}
1919
if isinstance(op, StandardScalerModel):
2020
C = operator.inputs[0].type.shape[1]
21-
attrs['offset'] = op.mean if op.getOrDefault("withMean") else [0.0] * C
22-
attrs['scale'] = [1.0 / x for x in op.std] if op.getOrDefault("withStd") else [1.0] * C
21+
attrs['offset'] = op.mean.toArray() if op.getOrDefault("withMean") else [0.0] * C
22+
attrs['scale'] = [1.0 / x for x in op.std.toArray()] if op.getOrDefault("withStd") else [1.0] * C
2323
elif isinstance(op, MinMaxScalerModel):
2424
epsilon = 1.0e-8 # to avoid dividing by zero
2525
attrs['offset'] = [x for x in op.originalMin]

tests/sparkml/test_scaler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_standard_scaler(self):
7575
(1, Vectors.dense([2.0, 1.1, 1.0]),),
7676
(2, Vectors.dense([3.0, 10.1, 3.0]),)
7777
], ["id", "features"])
78-
scaler = StandardScaler(inputCol='features', outputCol='scaled_features')
78+
scaler = StandardScaler(inputCol='features', outputCol='scaled_features', withStd=True, withMean=True)
7979
model = scaler.fit(data)
8080

8181
# the input names must match the inputCol(s) above

0 commit comments

Comments
 (0)