holdenk commented on a change in pull request #23741:
[SPARK-22798][PYTHON][ML]Add multiple column support to PySpark StringIndexer
URL: https://github.com/apache/spark/pull/23741#discussion_r255173464
##########
File path: python/pyspark/ml/feature.py
##########
@@ -2371,16 +2372,37 @@ class StringIndexer(JavaEstimator,
_StringIndexerParams, JavaMLReadable, JavaMLW
>>> sorted(set([(i[0], i[1]) for i in result.select(result.id,
result.indexed).collect()]),
... key=lambda x: x[0])
[(0, 0.0), (1, 1.0), (2, 2.0), (3, 0.0), (4, 0.0), (5, 2.0)]
+ >>> testData = sc.parallelize([Row(id=0, label1="a", label2="e"),
+ ... Row(id=1, label1="b", label2="f"),
+ ... Row(id=2, label1="c", label2="e"),
+ ... Row(id=3, label1="a", label2="f"),
+ ... Row(id=4, label1="a", label2="f"),
+ ... Row(id=5, label1="c", label2="f")], 3)
+ >>> multiRowDf = spark.createDataFrame(testData)
+ >>> inputs = ["label1", "label2"]
+ >>> outputs = ["index1", "index2"]
+ >>> stringIndexer = StringIndexer(inputCols=inputs, outputCols=outputs)
+ >>> model = stringIndexer.fit(multiRowDf)
+ >>> result = model.transform(multiRowDf)
+ >>> sorted(set([(i[0], i[1], i[2]) for i in result.select(result.id,
result.index1,
+ ... result.index2).collect()]), key=lambda x: x[0])
+ [(0, 0.0, 1.0), (1, 2.0, 0.0), (2, 1.0, 1.0), (3, 0.0, 0.0), (4, 0.0,
0.0), (5, 1.0, 0.0)]
+ >>> fromlabelsModel = StringIndexerModel.from_ArrayOfLabels([["a", "b",
"c"], ["e", "f"]],
+ ... inputCols=inputs, outputCols=outputs)
+ >>> result = fromlabelsModel.transform(multiRowDf)
+ >>> sorted(set([(i[0], i[1], i[2]) for i in result.select(result.id,
result.index1,
+ ... result.index2).collect()]), key=lambda x: x[0])
+ [(0, 0.0, 0.0), (1, 1.0, 1.0), (2, 2.0, 0.0), (3, 0.0, 1.0), (4, 0.0,
1.0), (5, 2.0, 1.0)]
.. versionadded:: 1.4.0
"""
@keyword_only
- def __init__(self, inputCol=None, outputCol=None, handleInvalid="error",
- stringOrderType="frequencyDesc"):
+ def __init__(self, inputCol=None, outputCol=None, inputCols=None,
outputCols=None,
Review comment:
I'm worried about adding `inputCols` and `outputCols` before `handleInvalid`
if anyones using positional constructors and had specified a value for
handleInvalid this could fail.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]