You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by yanboliang <gi...@git.apache.org> on 2016/11/25 08:49:29 UTC

[GitHub] spark pull request #16011: [SPARK-18587][ML] Remove handleInvalid from Quant...

GitHub user yanboliang opened a pull request:

    https://github.com/apache/spark/pull/16011

    [SPARK-18587][ML] Remove handleInvalid from QuantileDiscretizer

    ## What changes were proposed in this pull request?
    HandleInvalid only happens when ```Bucketizer``` transforming a dataset which contains NaN, however, when the training dataset containing NaN, ```QuantileDiscretizer``` will always ignore them. So we should keep ```handleInvalid``` in ```Bucketizer``` and remove it from ```QuantileDiscretizer```.
    
    ## How was this patch tested?
    Existing tests.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/yanboliang/spark spark-18587

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/16011.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 #16011
    
----
commit d3c3c3b0a3f59bf099df9377dee1e9db49652fe9
Author: Yanbo Liang <yb...@gmail.com>
Date:   2016-11-25T08:47:50Z

    Remove handleInvalid from QuantileDiscretizer

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark pull request #16011: [SPARK-18587][ML] Remove handleInvalid from Quant...

Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang closed the pull request at:

    https://github.com/apache/spark/pull/16011


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    When I did QA work for 2.1, I found the parameter ``` handleInvalid``` is disorienting. For example, the default behavior of ```QuantileDiscretizer``` to handle invalid value (i.e. NaN) is throwing error. So users expect errors if running against the following code.
    ```
    val data = Array(-0.9, -0.5, -0.3, 0.0, 0.2, 0.5, 0.9, Double.NaN, Double.NaN, Double.NaN)
    val df = data.toSeq.toDF("input")
    
    val discretizer = new QuantileDiscretizer()
          .setInputCol("input")
          .setOutputCol("result")
          .setNumBuckets(3)
    
    val model = discretizer.fit(df)
    println(model.getSplits.mkString(","))
    ```
    However, the above code can work well w/o any error thrown. 
    I'm OK with not make this change, but we should clarify it more clear in document. Thanks.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    @MLnick Yeah, I think this is the most common case that copying Params from estimators to models. However, I also found some algorithms do not comply this rule, such as ```ALS``` which has ```ALSParams``` and ```ALSModelParams``` for estimator and model separately.
    
    I think we can set params to models not via estimator, for example:
    ```
    val discretizer = new QuantileDiscretizer()
    val pipeline = new Pipeline().setStages(Array(discretizer))
    val model = pipeline.fit(df)
    model.stages(0).asInstanceOf[Bucketizer].setHandleInvalid("skip")
    ```
    I know this way is a little tricky, a better way may be we can have ```QuantileDiscretizerModel``` which is produced by ```QuantileDiscretizer```.
    Think more about it, ```Bucketizer``` is a separate transformer which mainly has two params(```splits``` and ```handleInvalid```) can be set. Users can provides candidates for these two params when doing cross validation to select the best model. But if we constrict it must be produced by ```QuantileDiscretizer```, the ```splits``` would be a member variable of the model rather than a param. From this perspective, it's more make sense to see ```Bucketizer``` as a separate transformer.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    **[Test build #69155 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/69155/consoleFull)** for PR 16011 at commit [`d3c3c3b`](https://github.com/apache/spark/commit/d3c3c3b0a3f59bf099df9377dee1e9db49652fe9).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    Merged build finished. Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by MLnick <gi...@git.apache.org>.
Github user MLnick commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    I don't think this is correct. The idea is `QuantileDiscretizer` skips NaN when creating the buckets, but there will still be an error thrown during `transform` (rather than `fit`) if NaNs are in data. Hence the test cases intercepting the error. I think the test cases show it works, no?
    
    e.g.
    
    `model.transform(df).show` throws:
    
    ```
    ...
    Caused by: org.apache.spark.SparkException: Bucketizer encountered NaN value. To handle or skip NaNs, try setting Bucketizer.handleInvalid.
      at org.apache.spark.ml.feature.Bucketizer$.binarySearchForBuckets(Bucketizer.scala:188)
      at org.apache.spark.ml.feature.Bucketizer$$anonfun$1.apply$mcDD$sp(Bucketizer.scala:115)
      at org.apache.spark.ml.feature.Bucketizer$$anonfun$1.apply(Bucketizer.scala:114)
      at org.apache.spark.ml.feature.Bucketizer$$anonfun$1.apply(Bucketizer.scala:114)
    ```
    
    Setting the param works:
    
    ```
    scala> model.setHandleInvalid("skip").transform(df).show
    +-----+------+
    |input|result|
    +-----+------+
    | -0.9|   0.0|
    | -0.5|   0.0|
    | -0.3|   1.0|
    |  0.0|   1.0|
    |  0.2|   2.0|
    |  0.5|   2.0|
    |  0.9|   2.0|
    +-----+------+
    
    
    scala> model.setHandleInvalid("keep").transform(df).show
    +-----+------+
    |input|result|
    +-----+------+
    | -0.9|   0.0|
    | -0.5|   0.0|
    | -0.3|   1.0|
    |  0.0|   1.0|
    |  0.2|   2.0|
    |  0.5|   2.0|
    |  0.9|   2.0|
    |  NaN|   3.0|
    |  NaN|   3.0|
    |  NaN|   3.0|
    +-----+------+
    ```


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    @MLnick Your description is totally correct. However, the ```model``` you used in your example is type of ```Bucketizer```. I will keep ```handleInvalid``` in ```Bucketizer```. In the current ML code, ```QuantileDiscretizer```(which is an estimator) will produce ```Bucketizer```(which is a model), and the invalid data handling only happens when you use ```Bucketizer``` to transform some data(may be not the same data used for training). When you run ```QuantileDiscretizer```, all NaN values will be ignored and no any error raised. That is the cause why I propose to remove ```handleInvalid``` from ```QuantileDiscretizer```.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by MLnick <gi...@git.apache.org>.
Github user MLnick commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    Typically the estimator Params are copied to the model though. How do you
    propose to set the handle invalid param in say a pipeline?
    On Fri, 25 Nov 2016 at 18:38, Yanbo Liang <no...@github.com> wrote:
    
    > @MLnick <https://github.com/MLnick> Your description is totally correct.
    > However, the model you used in your example is type of Bucketizer. I will
    > keep handleInvalid in Bucketizer. In the current ML code,
    > QuantileDiscretizer(which is an estimator) will produce Bucketizer(which
    > is a model), and the invalid data handling only happens when you use
    > Bucketizer to transform some data(may be not the same data used for
    > training). When you run QuantileDiscretizer, all NaN values will be
    > ignored and no any error raised. That is the cause why I propose to remove
    > handleInvalid from QuantileDiscretizer.
    >
    > \u2014
    > You are receiving this because you were mentioned.
    > Reply to this email directly, view it on GitHub
    > <https://github.com/apache/spark/pull/16011#issuecomment-262993285>, or mute
    > the thread
    > <https://github.com/notifications/unsubscribe-auth/AA_SB78XJugGohjiV29JR5jsk42BDoxUks5rBw8EgaJpZM4K8OHI>
    > .
    >



---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    That's OK. I will improve the docs in another 2.1 QA PR and close this one. Thanks for all your clarification. @MLnick @jkbradley 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    cc @jkbradley @srowen @VinceShieh @sethah 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/69155/
    Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by MLnick <gi...@git.apache.org>.
Github user MLnick commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    As far as I recall, the idea is that the `Bucketizer` can be used standalone, and because the `QuantileDiscretizer` itself produced the same thing as a bucketizer, it was used as the model rather than having a dedicated `QuantileDiscretizerModel`.
    
    `Bucketizer` is already a separate transformer (it is not required to be produced by a `QuantileDiscretizer`), since it's a `Model` and the constructor is public (by design). So it by itself can be used in a pipeline, and the `splits` param could be selected via cross-validation (for example).
    
    What you propose here makes using `QuantileDiscretizer` and a non-default `handleInvalid` param together with cross-validation impossible. In addition, as you've pointed out in your code example above, this would force a pretty clunky "workaround" to set the `handleInvalid` param in a pipeline.
    
    Why do this? What is the actual problem with what exists currently? To me it seems better the way it is. Also, I don't see any major benefit to adding a new `QuantileDiscretizerModel`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by jkbradley <gi...@git.apache.org>.
Github user jkbradley commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    I agree with @MLnick that we should not make this change.  We need users to be able to set all Params in Estimators, including the Params of the Models they produce.  If this is confusing for QuantileDiscretizer, then let's improve the docs.  Thanks!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] spark issue #16011: [SPARK-18587][ML] Remove handleInvalid from QuantileDisc...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/16011
  
    **[Test build #69155 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/69155/consoleFull)** for PR 16011 at commit [`d3c3c3b`](https://github.com/apache/spark/commit/d3c3c3b0a3f59bf099df9377dee1e9db49652fe9).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org