You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by actuaryzhang <gi...@git.apache.org> on 2017/05/03 06:04:38 UTC

[GitHub] spark pull request #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-...

GitHub user actuaryzhang opened a pull request:

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

    [SPARK-20574][ML] Allow Bucketizer to handle non-Double column

    ## What changes were proposed in this pull request?
    Bucketizer currently requires input column to be Double, but the logic should work on any numeric data types. Many practical problems have integer/float data types, and it could get very tedious to manually cast them into Double before calling bucketizer. This PR extends bucketizer to handle all numeric types.  
    
    ## How was this patch tested?
    New test.

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

    $ git pull https://github.com/actuaryzhang/spark bucketizer

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

    https://github.com/apache/spark/pull/17840.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 #17840
    
----
commit 7d93d5ab3d84d04c0636d9128215881f9d00a479
Author: Wayne Zhang <ac...@uber.com>
Date:   2017-05-03T04:02:33Z

    allow bucketizer to work for non-double column

commit a86fbde996afb1aed49c10a5785d934b4c12b2a2
Author: Wayne Zhang <ac...@uber.com>
Date:   2017-05-03T06:01:21Z

    update test for non-Double types

----


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    **[Test build #76409 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/76409/testReport)** for PR 17840 at commit [`a86fbde`](https://github.com/apache/spark/commit/a86fbde996afb1aed49c10a5785d934b4c12b2a2).


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    **[Test build #76459 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/76459/testReport)** for PR 17840 at commit [`d149350`](https://github.com/apache/spark/commit/d149350d73fcc4f576880730661fd688fed8fc07).
     * 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 pull request #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-...

Posted by MLnick <gi...@git.apache.org>.
Github user MLnick commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17840#discussion_r114773677
  
    --- Diff: mllib/src/test/scala/org/apache/spark/ml/feature/BucketizerSuite.scala ---
    @@ -162,6 +165,28 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa
           .setSplits(Array(0.1, 0.8, 0.9))
         testDefaultReadWrite(t)
       }
    +
    +  test("Bucket non-double numeric features") {
    +    val splits = Array(-3.0, 0.0, 3.0)
    +    val data = Array(-2.0, -1.0, 0.0, 1.0, 2.0)
    +    val expectedBuckets = Array(0.0, 0.0, 1.0, 1.0, 1.0)
    +    val dataFrame: DataFrame = data.zip(expectedBuckets).toSeq.toDF("feature", "expected")
    +
    +    val bucketizer: Bucketizer = new Bucketizer()
    +      .setInputCol("feature")
    +      .setOutputCol("result")
    +      .setSplits(splits)
    +
    +    val types = Seq(ShortType, IntegerType, LongType, FloatType)
    --- End diff --
    
    Other tests for supporting numeric types have included `DecimalType` - often `DecimalType(10, 0)`, as well as `ByteType`. See the various Estimator tests which use `MLTestingUtils.genClassifDFWithNumericLabelCol` and `MLTestingUtils.genRegressionDFWithNumericLabelCol`


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-...

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

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


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    Merged into master and branch-2.0. 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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/76459/
    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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

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


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    Merged build finished. Test FAILed.


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    **[Test build #76420 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/76420/testReport)** for PR 17840 at commit [`b4a5b6f`](https://github.com/apache/spark/commit/b4a5b6f5e40a5ad711c9a759227584a17e35fc24).
     * 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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    @yinxusen  @srowen @mengxr @jkbradley @VinceShieh @yanboliang 
    
    The example below shows failure of Bucketizer on integer data. 
    ```
    val splits = Array(-3.0, 0.0, 3.0)
    val data: Array[Int] = Array(-2, -1, 0, 1, 2)
    val expectedBuckets = Array(0.0, 0.0, 1.0, 1.0, 1.0)
    val dataFrame = data.zip(expectedBuckets).toSeq.toDF("feature", "expected")
    val bucketizer = new Bucketizer()
      .setInputCol("feature")
      .setOutputCol("result")
      .setSplits(splits)
    bucketizer.transform(dataFrame)  
    
    java.lang.IllegalArgumentException: requirement failed: Column feature must be of type DoubleType but was actually IntegerType.
    ```
    



---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-...

Posted by yanboliang <gi...@git.apache.org>.
Github user yanboliang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17840#discussion_r114736255
  
    --- Diff: mllib/src/test/scala/org/apache/spark/ml/feature/BucketizerSuite.scala ---
    @@ -162,6 +165,28 @@ class BucketizerSuite extends SparkFunSuite with MLlibTestSparkContext with Defa
           .setSplits(Array(0.1, 0.8, 0.9))
         testDefaultReadWrite(t)
       }
    +
    +  test("Bucket non-double numeric features") {
    +    val splits = Array(-3.0, 0.0, 3.0)
    +    val data = Array(-2.0, -1.0, 0.0, 1.0, 2.0)
    +    val expectedBuckets = Array(0.0, 0.0, 1.0, 1.0, 1.0)
    +    val dataFrame: DataFrame = data.zip(expectedBuckets).toSeq.toDF("feature", "expected")
    +
    +    val bucketizer: Bucketizer = new Bucketizer()
    +      .setInputCol("feature")
    +      .setOutputCol("result")
    +      .setSplits(splits)
    +
    +    val types = Seq(ShortType, IntegerType, LongType, FloatType)
    +    for (mType <- types) {
    +      val df = dataFrame.withColumn("feature", col("feature").cast(mType))
    +      bucketizer.transform(df).select("result", "expected").collect().foreach {
    +        case Row(x: Double, y: Double) =>
    +          assert(x === y, "The feature value is not correct after bucketing in type " +
    --- End diff --
    
    ```feature value``` -> ```result```


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    Weird failure message, the log shows all tests 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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/76420/
    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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    Thanks @yanboliang and @MLnick.
    I have included the additional numeric types and updated the error msg. 



---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    **[Test build #76459 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/76459/testReport)** for PR 17840 at commit [`d149350`](https://github.com/apache/spark/commit/d149350d73fcc4f576880730661fd688fed8fc07).


---
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 #17840: [SPARK-20574][ML] Allow Bucketizer to handle non-Double ...

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

    https://github.com/apache/spark/pull/17840
  
    **[Test build #76420 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/76420/testReport)** for PR 17840 at commit [`b4a5b6f`](https://github.com/apache/spark/commit/b4a5b6f5e40a5ad711c9a759227584a17e35fc24).


---
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