Github user zhengruifeng commented on a diff in the pull request:
https://github.com/apache/spark/pull/17384#discussion_r109074112
--- Diff:
mllib/src/test/scala/org/apache/spark/ml/regression/IsotonicRegressionSuite.scala
---
@@ -189,6 +191,47 @@ class IsotonicRegressionSuite
assert(expected.predictions === actual.predictions)
}
}
+
+ test("Besides VectorUDT, should support all NumericType features, and
not support other types") {
+ val df = generateIsotonicInput(Seq(1, 2, 3))
+ val ir = new IsotonicRegression()
+
+ val expected = ir.fit(df)
+ val expectedPrediction =
+
expected.transform(df).select("prediction").map(_.getDouble(0)).collect()
+
+ val types =
+ Seq(ShortType, LongType, IntegerType, FloatType, ByteType,
DoubleType, DecimalType(10, 0))
+
+ types.foreach { t =>
+ val df2 = df.select(col("label"), col("features").cast(t),
col("weight"))
+
+ val actual = ir.fit(df2)
+ assert(expected.boundaries === actual.boundaries)
+ assert(expected.predictions === actual.predictions)
+
+ val actualPrediction =
+
actual.transform(df2).select("prediction").map(_.getDouble(0)).collect()
+ assert(expectedPrediction === actualPrediction)
+ }
+
+ val dfWithStringFeatures =
+ df.select(col("label"), col("features").cast(StringType),
col("weight"))
+
+ val thrown = intercept[IllegalArgumentException] {
+ ir.fit(dfWithStringFeatures)
+ }
+ assert(thrown.getMessage.contains(
+ "Column features must be of type NumericType or VectorUDT," +
+ " but was actually of type StringType"))
+
+ val thrown2 = intercept[IllegalArgumentException] {
+ expected.transform(dfWithStringFeatures)
+ }
+ assert(thrown2.getMessage.contains(
+ "Column features must be of type NumericType or VectorUDT," +
+ " but was actually of type StringType"))
+ }
--- End diff --
`checkNumericTypes` only test `fit` method on `labelCol` and `weightCol`.
`IsotonicRegressor` is the only algorithm which need to test both `fit` and
`transform` on `featureCol`. So I prefer not to use `checkNumericTypes`. Thanks
for your review
---
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]