Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

huaxingao
Copy link
Contributor

What changes were proposed in this pull request?

change PySpark ml Params._clear to Params.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.

@huaxingao
Copy link
Contributor Author

@BryanCutler @srowen
Could you please review? Thanks a lot!

@SparkQA
Copy link

SparkQA commented Oct 15, 2019

Test build #112120 has finished for PR 26130 at commit a555474.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@BryanCutler
Copy link
Member

@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]|
+-----+------+

Copy link
Member

@BryanCutler BryanCutler left a 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

@SparkQA
Copy link

SparkQA commented Oct 15, 2019

Test build #112128 has finished for PR 26130 at commit a21f39c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

Copy link
Member

@srowen srowen left a 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.

@zhengruifeng
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Oct 17, 2019

Test build #4900 has finished for PR 26130 at commit a21f39c.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

self.assertEqual(model.getOutputCol(), "scaled")
model.clear(model.outputCol)
self.assertFalse(model.isSet(model.outputCol))
self.assertEqual(model.getOutputCol()[:12], 'MaxAbsScaler')
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

@BryanCutler BryanCutler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BryanCutler
Copy link
Member

merged to master, thanks @huaxingao !

@huaxingao
Copy link
Contributor Author

Thank you all for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants