-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-29464][PYTHON][ML] PySpark ML should expose Params.clear() to unset a user supplied Param #26130
Conversation
…unset a user supplied Param
@BryanCutler @srowen |
Test build #112120 has finished for PR 26130 at commit
|
@huaxingao I think there is a problem when the Java object has the param set, then it is cleared in Python but not Java. For example: In [4]: >>> from pyspark.ml.linalg import Vectors
...: >>> df = spark.createDataFrame([(Vectors.dense([1.0]),), (Vectors.dense([2.0]),)], ["a"])
...: >>> maScaler = MaxAbsScaler(inputCol="a", outputCol="scaled")
...: >>> model = maScaler.fit(df)
...: >>> model.setOutputCol("scaledOutput")
Out[4]: MaxAbsScaler_f91118f1dd81
In [7]: model.clear(model.outputCol)
In [9]: model.getOutputCol()
Out[9]: 'MaxAbsScaler_f91118f1dd81__output'
In [11]: model.transform(df).show()
+-----+------+
| a|scaled|
+-----+------+
|[1.0]| [0.5]|
|[2.0]| [1.0]|
+-----+------+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to sync with Java after clear
Test build #112128 has finished for PR 26130 at commit
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks OK to me pending tests if it looks good to you both.
retest this please |
Test build #4900 has finished for PR 26130 at commit
|
self.assertEqual(model.getOutputCol(), "scaled") | ||
model.clear(model.outputCol) | ||
self.assertFalse(model.isSet(model.outputCol)) | ||
self.assertEqual(model.getOutputCol()[:12], 'MaxAbsScaler') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, could you check that outputCol
is equal to the default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, I guess there isn't a way to get the default value directly. This is fine then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
merged to master, thanks @huaxingao ! |
Thank you all for the help! |
What changes were proposed in this pull request?
change PySpark ml
Params._clear
toParams.clear
Why are the changes needed?
PySpark ML currently has a private _clear() method that will unset a param. This should be made public to match the Scala API and give users a way to unset a user supplied param.
Does this PR introduce any user-facing change?
Yes. PySpark ml
Params._clear
--->Params.clear
How was this patch tested?
Add test.