Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-11861][ML] Add feature importances for decision trees #9912

Closed
wants to merge 9 commits into from

Conversation

sethah
Copy link
Contributor

@sethah sethah commented Nov 23, 2015

This patch adds an API entry point for single decision tree feature importances.

@SparkQA
Copy link

SparkQA commented Nov 23, 2015

Test build #46540 has finished for PR 9912 at commit 9378203.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sethah
Copy link
Contributor Author

sethah commented Nov 23, 2015

After some further review, it seems generally accepted in the literature that this method of computing feature importance for decision trees has high variance due to correlated predictors. Some methods for compensating this would be to incorporate surrogate splits in the computation, but surrogate splits are not currently tracked in spark.ml.

Despite the shortcomings, since scikit-learn and R (package: rpart) both offer it, I think this is still appropriate. We could include a warning message... thoughts?

@SparkQA
Copy link

SparkQA commented Nov 23, 2015

Test build #46550 has finished for PR 9912 at commit 0e8b223.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Feb 16, 2016

Test build #51383 has finished for PR 9912 at commit 0c80d8e.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@jkbradley
Copy link
Member

Thanks for the PR! I'd like to get this into 2.0. I just had a couple of small comments.

*
* This generalizes the idea of "Gini" importance to other losses,
* following the explanation of Gini importance from "Random Forests" documentation
* by Leo Breiman and Adele Cutler, and following the implementation from scikit-learn.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for including a note about feature importance having high variance for individual trees, and recommending that users use Random Forests to calculate importance more precisely (here and in DecisionTreeRegressor)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a note in the docs for DecisionTreeRegressor and DecisionTreeClassifier. I can update the format or the wording if needed.

val categoricalFeatures = Map.empty[Int, Int]
val df: DataFrame = TreeTests.setMetadata(data, categoricalFeatures, numClasses)

val importances = rf.fit(df).featureImportances
val mostImportantFeature = importances.argmax
assert(mostImportantFeature === 1)
assert(importances.toArray.sum === 1.0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the feature importance tests here, as well, with additional checks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@SparkQA
Copy link

SparkQA commented Mar 6, 2016

Test build #52531 has finished for PR 9912 at commit cc2eb44.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA
Copy link

SparkQA commented Mar 7, 2016

Test build #52573 has finished for PR 9912 at commit 57cbfb5.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sethah
Copy link
Contributor Author

sethah commented Mar 8, 2016

@jkbradley I addressed comments and added @Since annotations to decision trees and random forests. Let me know if you see anything else, thanks!

@SparkQA
Copy link

SparkQA commented Mar 8, 2016

Test build #52673 has finished for PR 9912 at commit 30637d4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@jkbradley
Copy link
Member

LGTM
Thanks a lot for the PR!
Merging with master

@asfgit asfgit closed this in e1772d3 Mar 9, 2016
roygao94 pushed a commit to roygao94/spark that referenced this pull request Mar 22, 2016
This patch adds an API entry point for single decision tree feature importances.

Author: sethah <seth.hendrickson16@gmail.com>

Closes apache#9912 from sethah/SPARK-11861.
@Malouke
Copy link

Malouke commented May 5, 2017

Hi ,
Thank you for Work but il don t Knowles where il can found documentation about the features importances???
I use pyspark 1.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants