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

    https://github.com/apache/spark/pull/12374#discussion_r70305428
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/tree/impl/RandomForestSuite.scala ---
    @@ -137,14 +137,47 @@ class RandomForestSuite extends SparkFunSuite with 
MLlibTestSparkContext {
         {
           val fakeMetadata = new DecisionTreeMetadata(1, 0, 0, 0,
             Map(), Set(),
    -        Array(3), Gini, QuantileStrategy.Sort,
    +        Array(2), Gini, QuantileStrategy.Sort,
             0, 0, 0.0, 0, 0
           )
           val featureSamples = Array(0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
2).map(_.toDouble)
           val splits = 
RandomForest.findSplitsForContinuousFeature(featureSamples, fakeMetadata, 0)
           assert(splits.length === 1)
           assert(splits(0) === 1.0)
         }
    +
    +    // find splits for constant feature
    +    {
    +      val fakeMetadata = new DecisionTreeMetadata(1, 0, 0, 0,
    +        Map(), Set(),
    +        Array(3), Gini, QuantileStrategy.Sort,
    +        0, 0, 0.0, 0, 0
    +      )
    +      val featureSamples = Array(0, 0, 0).map(_.toDouble)
    +      val featureSamplesEmpty = Array.empty[Double]
    +      val splits = 
RandomForest.findSplitsForContinuousFeature(featureSamples, fakeMetadata, 0)
    +      assert(splits === Array[Double]())
    +      val splitsEmpty =
    +        RandomForest.findSplitsForContinuousFeature(featureSamplesEmpty, 
fakeMetadata, 0)
    +      assert(splitsEmpty === Array[Double]())
    +    }
    +  }
    +
    +  test("train with constant features") {
    +    val lp = LabeledPoint(1.0, Vectors.dense(0.0, 0.0, 0.0))
    +    val data = Array.fill(5)(lp)
    +    val rdd = sc.parallelize(data)
    +    val strategy = new OldStrategy(
    +          OldAlgo.Classification,
    +          Gini,
    +          maxDepth = 2,
    +          numClasses = 100,
    +          maxBins = 100,
    +          categoricalFeaturesInfo = Map(0 -> 2, 1 -> 5))
    --- End diff --
    
    I am using this to not only test continuous features, but categorical ones 
as well. I think we should leave 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