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

    https://github.com/apache/spark/pull/13440#discussion_r104822632
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/DecisionTreeClassifierSuite.scala
 ---
    @@ -237,6 +237,41 @@ class DecisionTreeClassifierSuite
         compareAPIs(rdd, dt, categoricalFeatures = Map.empty[Int, Int], 
numClasses)
       }
     
    +  test("split quality using chi-squared and minimum gain") {
    +    // Generate a data set where the 1st feature is useful and the others 
are noise
    +    val features = Vector.fill(200) {
    +      Array.fill(3) { scala.util.Random.nextInt(2).toDouble }
    +    }
    +    val labels = features.map { fv =>
    +      LabeledPoint(if (fv(0) == 1.0) 1.0 else 0.0, Vectors.dense(fv))
    +    }
    +    val rdd = sc.parallelize(labels)
    +
    +    // two-class learning problem
    +    val numClasses = 2
    +    // all binary features
    +    val catFeatures = Map(Vector.tabulate(features.head.length) { j => (j, 
2) } : _*)
    +
    +    // Chi-squared split quality with a p-value threshold of 0.01 should 
allow
    +    // only the first feature to be used since the others are uncorrelated 
noise
    +    val train: DataFrame = TreeTests.setMetadata(rdd, catFeatures, 
numClasses)
    +    val dt = new DecisionTreeClassifier()
    +      .setImpurity("chisquared")
    +      .setMaxDepth(5)
    +      .setMinInfoGain(0.01)
    +    val treeModel = dt.fit(train)
    +
    +    // The tree should use exactly one of the 3 features: featue(0)
    --- End diff --
    
    👍 


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