GitHub user sethah opened a pull request:
https://github.com/apache/spark/pull/11099
[SPARK-13068][PYSPARK][ML]
This patch adds the following changes:
* Creates type specific subclasses of `pyspark.ml.param.Param` with
specialized validation for each type. This mirrors the param subclasses in
Scala.
* Adds an optional parameter `isValid` to the `Param` constructor which is
a function that maps a parameter value to a Boolean. (e.g. `lambda value: value
>= 0`)
* Adds `_validate` and `_convertAndValidate` functions to `Param` class
which help with type conversions and validation when param values are set.
* Adds a `ParamValidators` class for factory validation methods, mirroring
Scala.
* Changes all existing ml params to use the type specific subclasses.
* Adds unit tests to verify that parameter type conversion occurs.
I think this is the best way to provide robust type checking/conversion
mechanisms in Python without resorting to a confusing public API and to support
arbitrary future cases for params. Overall, this change aims to make the Python
params more closely match the param implementations in Scala.
I would be happy to split this PR if it makes it more manageable, though I
think the changes are intertwined.
Follow up work:
* Change the Param copy method to call `_set` instead of changing the param
map directly. [SPARK-12944](https://issues.apache.org/jira/browse/SPARK-12944)
* Change all param setters to use private `_set` function instead of
changing param map directly.
cc @yanboliang @holdenk @davies
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/sethah/spark SPARK-13068
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/11099.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #11099
----
commit d4c3a1d591225a36eac55f865b297bd0d7385ecf
Author: sethah <[email protected]>
Date: 2016-02-04T22:58:19Z
python param subclasses and validation functions
commit a6c8dbed5a98bf1a6744259bc98005d8e0891b35
Author: sethah <[email protected]>
Date: 2016-02-04T23:55:02Z
cleaning up shared param codegen
commit 5b6ae3e149b5289262be6417a1b1c1c5ed37a094
Author: sethah <[email protected]>
Date: 2016-02-05T00:52:01Z
some doc strings and cleanup
commit 2796e0fa08aad44636988e46f494433c0e78b3f8
Author: sethah <[email protected]>
Date: 2016-02-05T19:31:04Z
adding tests
commit 30b052c2eb9b26723b3dda0f1ec45565112ecaf3
Author: sethah <[email protected]>
Date: 2016-02-05T21:56:37Z
minor cleanup
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]