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

    https://github.com/apache/spark/pull/13650#discussion_r70639350
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/regression/RandomForestRegressorSuite.scala
 ---
    @@ -105,6 +109,54 @@ class RandomForestRegressorSuite extends SparkFunSuite 
with MLlibTestSparkContex
           }
       }
     
    +  test("Random Forest variance") {
    +    val categoricalFeatures = Map.empty[Int, Int]
    +    val df: DataFrame = TreeTests.setMetadata(
    +      orderedLabeledPoints50_1000, categoricalFeatures, 0)
    +
    +    // RF with one tree should have the same variance as that of the tree.
    +    val rf = new RandomForestRegressor()
    +      .setImpurity("variance")
    +      .setMaxDepth(30)
    +      .setNumTrees(1)
    +      .setMaxBins(10)
    +      .setFeatureSubsetStrategy("all")
    +      .setSubsamplingRate(1.0)
    +      .setSeed(123)
    +
    +    val rfModel = rf.fit(df)
    +    val rfVariances = rfModel.transform(df).select("variance").collect()
    +
    +    val dt = new DecisionTreeRegressor()
    +      .setImpurity("variance")
    +      .setMaxDepth(30)
    +      .setMaxBins(10)
    +      .setSeed(123)
    +    val dtModel = dt.fit(df)
    +    val dtVariances = dtModel.transform(df).select("variance").collect()
    +    val nSamples = dtVariances.size
    +    (0 to nSamples - 1).foreach { i =>
    +      assert(rfVariances(i).getDouble(0) ~== dtVariances(i).getDouble(0) 
absTol 1e-6)
    +    }
    +
    +    rf.setMaxDepth(2)
    +    rf.setNumTrees(20)
    +    val rfNewModel = rf.fit(df)
    +    val results = rfNewModel.transform(df).select("features", 
"variance").collect()
    +    val features = col("features")
    --- End diff --
    
    This line is never used, remove it.


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

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

Reply via email to