GitHub user hhbyyh opened a pull request:
https://github.com/apache/spark/pull/17583
[SPARK-20271]Add FuncTransformer to simplify custom transformer creation
## What changes were proposed in this pull request?
Just to share some code I implemented to help easily create a custom
Transformer in one line of code,
e.g. ` val labelConverter = new FuncTransformer((i: Double) => if (i >= 1)
1 else 0) `
This was used in many of my projects and is pretty helpful (Maybe I'm
lazy..). The transformer can be saved/loaded as other transformer and can be
integrated into a pipeline normally. It can be used widely in many use cases
like conditional conversion(if...else...), , type conversion, to/from Array,
to/from Vector and many string ops.
Compared to `UnaryTransformer`, [(check the
example)](https://github.com/apache/spark/blob/39e2bad6a866d27c3ca594d15e574a1da3ee84cc/examples/src/main/scala/org/apache/spark/examples/ml/UnaryTransformerExample.scala#L56),
FuncTransformer will greatly simplify the custom Transformer.
`val shifter = new FuncTransformer((i: Double) => i + 1)`
## How was this patch tested?
No unit test is added for now as I'm not sure if this is something that
would interests the community.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/hhbyyh/spark funcTransformer
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/17583.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 #17583
----
commit 4d5fbc7290f3eec252a919b8ac9b4b71ece3e614
Author: Yuhao Yang <[email protected]>
Date: 2017-04-10T01:24:18Z
func transformer
commit 9c7e731361586c2fdb929e37f170675e9503dd22
Author: Yuhao Yang <[email protected]>
Date: 2017-04-10T03:11:48Z
rename in example
----
---
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]