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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]