Github user BenFradet commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10355#discussion_r57241509
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/RandomForestClassifierSuite.scala
 ---
    @@ -178,6 +179,34 @@ class RandomForestClassifierSuite extends 
SparkFunSuite with MLlibTestSparkConte
         assert(importances.toArray.forall(_ >= 0.0))
       }
     
    +  test("should support all NumericType labels") {
    +    val dfs = MLTestingUtils.genClassifDFWithNumericLabelCol(sqlContext, 
"label", "features")
    +
    +    val rf = new RandomForestClassifier().setFeaturesCol("features")
    +
    +    val expected = rf.setLabelCol("label")
    +      .fit(TreeTests.setMetadata(dfs(DoubleType), 2, "label"))
    +    dfs.keys.filter(_ != DoubleType).foreach { t =>
    +      TreeTests.checkEqual(expected,
    +        rf.setLabelCol("label").fit(TreeTests.setMetadata(dfs(t), 2, 
"label")))
    +    }
    +  }
    +
    +  test("shouldn't support non NumericType labels") {
    --- End diff --
    
    Here's what I managed to make work:
    
    ```scala
      def checkNumericTypes[M <: RegressionModel[_, M], T <: Regressor[_, _, 
M]](
          regressor: T, sqlContext: SQLContext)(check: (M, M) => Unit): Unit = {
        val dfs = MLTestingUtils.genRegressionDFWithNumericLabelCol(sqlContext, 
"label", "features")
        
        val expected = regressor.fit(dfs(DoubleType))
        val actuals = dfs.keys.filter(_ != DoubleType).map(t => 
regressor.fit(dfs(t)))
        actuals.foreach(actual => check(expected, actual))
      }
    ```
    
    which could be used like:
    
    ```scala
    MLTestingUtils.checkNumericTypes[LinearRegressionModel, LinearRegression](
        new LinearRegression(), sqlContext) { (expected, actual) =>
          assert(expected.intercept === actual.intercept)
          assert(expected.coefficients === actual.coefficients)
        }
    ```


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

Reply via email to