Skip to content

add post-pruning for decision trees #6557

Closed

Description

@amueller

I frequently get asked about post-pruning. Often using single trees is important for interpretability, and post-pruning can help both interpretability and generalization performance.
[I'm surprised there is no open issue on this, but I couldn't find one]

Activity

  1. nelson-liu commented on Mar 17, 2016

    @nelson-liu
    Contributor

    I can give this a shot :)

  2. lesshaste commented on Mar 18, 2016

    @lesshaste

    The title of this issue is related #4630 .

  3. maniteja123 commented on Mar 18, 2016

    @maniteja123
    Contributor

    This issue #941 also seems to be proposing prune method to the tree but the code has considerably changed in the meantime I suppose.

  4. lesshaste commented on Mar 18, 2016

    @lesshaste

    On the topic of interpretability, there has also been published work on creating single decision trees from random forests. As counter-intuitive as this sounds, due to the non-optimality of standard decision tree algorithms, this can apparently give single decisions tree that are both interpretable and also better classifiers/regressors than you would get otherwise.

  5. qmaruf commented on Apr 5, 2016

    @qmaruf

    @amueller Could you please explain this issue a little bit? I want to work on this.

  6. amueller commented on May 21, 2016

    @amueller
    MemberAuthor

    actually maybe the first thing to do would be to add a stopping criterion based on mutual information...

  7. amueller commented on May 21, 2016

    @amueller
    MemberAuthor

    @lesshaste can you give a citation? (I had been thinking about that recently, damn, obviously it has been done ^^)

  8. lesshaste commented on May 21, 2016

    @lesshaste

    @amueller It has been a long time since I looked at this but:

    Section 2.2 of
    "Rule Extraction from Random Forest: the RF+HC Methods" by Morteza Mashayekhi and Robin Gras has all the relevant citations I know. Please let me know if you don't have access to this paper.

    On an only slightly related note, I remember looking at http://blog.datadive.net/interpreting-random-forests/ with some interest.

  9. glouppe commented on Jun 6, 2016

    @glouppe
    Contributor

    actually maybe the first thing to do would be to add a stopping criterion based on mutual information...

    An easy addition would be to stop the construction when p(t) i(t, s*) < beta, i.e. when the weighted impurity p(t) i(t, s*) for the best split s* becomes less than some user-defined threshold beta.

  10. ogrisel commented on Jun 6, 2016

    @ogrisel
    Member

    I frequently get asked about post-pruning. Often using single trees is important for interpretability, and post-pruning can help both interpretability and generalization performance.

    I think this can also be beneficial for some ensemble algorithms like (gradient) boosting although it's typically not increasing the predictive accuracy for bagging-style ensembles (e.g. random forests).

    Pruning might also be useful to save some memory and decrease prediction times a bit.

  11. nelson-liu commented on Jun 30, 2016

    @nelson-liu
    Contributor

    @amueller / others: @jmschrei and i met to discuss the issue of post-pruning a few weeks ago, and we were unsure of how it would fit in the current scikit-learn API. Generally, post-pruning needs a validation set, but this doesn't seem to fit nicely with how the library is currently organized (namely, issues like creation / origin of the validation set and whether this would be an argument to fit or a separate method come to mind). How were you thinking of this being implemented from an API point of view?
    For now, I'm working on looking through the splitter.pyx code and adding the early stopping criteria based on weighted impurity for GSoC while thinking about MAE.

  12. nelson-liu commented on Jun 30, 2016

    @nelson-liu
    Contributor

    Seems like there was some discussion about API issues in #941, but the tree module has changed quite a bit and perhaps we should have the discussion again. For one, we have parameters like max_leaf_nodes and max_depth to control growth of the tree a bit.

  13. nlgranger commented on Jun 30, 2016

    @nlgranger

    I would be inclined to set up pruning as a separate method. In fact, a separate function that takes a tree and returns the pruned version would be ok to begin with. This is the approach which is used in https://github.com/ajtulloch/sklearn-compiledtrees to generate optimized code for trees.

    @nelson-liu With regard to the regularization options, they sometimes lead to subtrees with all nodes belonging to the same class. While it is not pruning in the sense of regularization, it would be nice to have a function to get rid of these extra nodes that only add computational cost during prediction.

  14. 40 remaining items

  15. appleyuchi commented on Dec 3, 2018

    @appleyuchi

    @zanderbraam it's not CCP

  16. appleyuchi commented on Dec 8, 2018

    @appleyuchi

    Hi,all ,
    I have implemented:
    CCP(Cost Complexity Pruning) Algorithm on
    sklearn-CART-Classification-model in Python,

    ECP(Error Complexity Pruning) Algorithm on
    sklearn-CART-Regression-model in Python,

    here's the link:
    https://github.com/appleyuchi/Decision_Tree_Prune
    you may like it.

  17. amueller commented on Dec 8, 2018

    @amueller
    MemberAuthor

    @appleyuchi thanks!
    I find it a bit hard to follow the structure of the code, in particular given that file names and comments are in Chinese. There also seems to be a lot of duplicate code.

  18. nlgranger commented on Dec 13, 2018

    @nlgranger

    I don't work with DT anymore, but has anyone had a look at https://github.com/beedotkiran/randomforestpruning-ismm-2017 ? It seems relevant to this issue.

  19. nlgranger commented on Dec 13, 2018

    @nlgranger

    A tree is just a very small forest. Can't this implementation scale down to trees?

  20. amueller commented on Dec 13, 2018

    @amueller
    MemberAuthor

    @appleyuchi I'm not sure if I follow what you're saying but we will not adopt an implementation based on going to JSON. Any implementation in scikit-learn would have to work directly with the scikit-learn data structures.

  21. adrinjalali commented on Dec 14, 2018

    @adrinjalali
    Member

    @appleyuchi thanks for your efforts. Regarding how tricky it may be to implement this feature, we do recognize that touching the tree code base is not necessarily a trivial task. There have been efforts to change that and have a more readable implementation. Besides, this issue isn't labeled as "Easy" for that exact reason.

    I hope you find other issues that you may be interested in and you keep the good work on them :)

  22. added
    Moderate
    on Dec 14, 2018
  23. thomasjpfan commented on Dec 23, 2018

    @thomasjpfan
    Member

    I am working on this issue with a cost complexity pruning (CPP) algorithm. I see several tests that can be used to check tree pruning:

    1. Increasing alpha (in CPP) should result in smaller or equal number of nodes.
    2. Make sure the pruned tree is actually a subtree of the original tree.

    What other tests would be appropriate for tree pruning?

  24. zhenyu-zhou commented on Jul 26, 2019

    @zhenyu-zhou

    @appleyuchi Thanks for sharing! My concern is that, even as a Chinese, it's still pretty hard for me to follow the code. I guess it is better to have the code more modularized so that others can apply your implementation on any data sets.

  25. appleyuchi commented on Jul 26, 2019

    @appleyuchi

    @zhenyu-zhou
    Because almost all of you did NOT ever read the book《classification and regression trees》carefully.

    The first author of this book has already passed away so you can not contact him for questions.

    The defect of this book is discussed in
    http://www.dcc.fc.up.pt/~ltorgo/PhD/th4.pdf
    or
    http://www.doc88.com/p-6445227043649.html

    which point out that CCP/ECP algorithm-cross validation will fail for unbalanced and small datasets,
    you should understand the above academic materials before you implement it.

    I analyzed and summarized the defect in:

    https://blog.csdn.net/appleyuchi/article/details/84957220

    The Github link I provide for CCP/ECP is just "application style",NOT from sklearn's "bottom variable style",(the latter will be much more efficient and faster)
    so they reject.

    even as a Chinese, it's still pretty hard for me to follow the code. I guess it is better to have the code more modularized so that others can apply your implementation on any data sets.

    It can be applied on many datasets I have tested,I guess you even have NOT clicked in and read the instruction in the Github link

  26. zhenyu-zhou commented on Jul 26, 2019

    @zhenyu-zhou

    @appleyuchi

    But it can be applied on any datasets you want,I'm sure you even have NOT clicked in and read the instruction in the link

    You are ABSOLUTELY WRONG. To make it short, I just have one question for you: do you provide a clean API, like sklearn did?

    You shouldn't expect everyone to read every detail of your code before using it, and blame others for that, if you treat your code as a library as sklearn. That's one of the reasons they reject the code. Consider it when you are using other libraries, take sklearn as an example, if it only has a bunch of self-contained code for experiments, which requires a certain input format, without a general framework. You need to carefully examine the library code to determine how to split the main logic out and apply to your dataset. Will you use it? I acknowledge that the experiment is interesting, but it is not a library. I just want to kindly post sth in my mind to improve the code but it is too hard.

  27. appleyuchi commented on Jul 26, 2019

    @appleyuchi

    @zhenyu-zhou

    You shouldn't expect everyone to read every detail of your code before using it,and blame others for that,

    you misunderstand it ,what I said is material,not code.
    Note that it refers to a book,NOT the code I have written.

    I mean《classification and regression trees》is a famous book,not the code I wrote ,
    so that's not blame.and "you" refers to new contributors,NOT the existing member of sklearn.

    I just want to kindly post sth in my mind to improve the code but it is too hard.

    again,you should read the book carefully before you implement it.

    @zhenyu-zhou

    , if it only has a bunch of self-contained code for experiments, which requires a certain input format, without a general framework. You need to carefully examine the library code to determine how to split the main logic out and apply to your dataset.

    The API style has been dicussed several months ago when you have NOT been here,
    again,
    what I have implemented is"application style",NOT from"sklearn bottom data structure"

    Good Luck.
    问题

    ps:
    Notification from this issue has been cancelled,because I'm busy.
    @me will NOT take effect any longer.
    If you have any question ,contact me via Email please.

  28. yml-blog commented on Jun 13, 2020

    @yml-blog

    @ameuller @glouppe @GaelVaroquaux any opinion on the api for post pruning? I see these three options, the first of which seems the best to me. Just wanted to get some clarification before I start to think about working on this:

    • options given to the tree constructor are then taken into account by .fit
    • a separate .prune or .post_prune method has to be called after fitting
    • a separate prune_tree or post_prune_tree function takes the tree and returns another pruned tree
      do you have any code for this?
      Thanks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ModerateNew Featurehelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions