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

    https://github.com/apache/spark/pull/9912#discussion_r54981161
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/classification/DecisionTreeClassifierSuite.scala
 ---
    @@ -309,6 +309,27 @@ class DecisionTreeClassifierSuite extends 
SparkFunSuite with MLlibTestSparkConte
         }
       }
     
    +  test("Feature importance with toy data") {
    +    val dt = new DecisionTreeClassifier()
    +      .setImpurity("gini")
    +      .setMaxDepth(3)
    +      .setSeed(123)
    +
    +    // In this data, feature 1 is very important.
    +    val data: RDD[LabeledPoint] = TreeTests.featureImportanceData(sc)
    +    val numFeatures = data.first().features.size
    +    val categoricalFeatures = (0 to numFeatures).map(i => (i, 2)).toMap
    +    val df = TreeTests.setMetadata(data, categoricalFeatures, 2)
    +
    +    val model = dt.fit(df)
    +
    +    // copied model must have the same parent.
    +    MLTestingUtils.checkCopy(model)
    +    val importances = model.featureImportances
    +    val mostImportantFeature = importances.argmax
    +    assert(mostImportantFeature === 1)
    --- End diff --
    
    Could you also please check that the importances are >= 0 and sum to 1?  
(same for DecisionTreeRegressorSuite)


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