Skip to content

RandomForest{Classifier,Regressor} split criterion documentation #27159

Closed

Description

@howarth

Describe the issue linked to the documentation

There's no where in the documentation that explains what method is used to identify which values to consider as candidate splits. For example, for regression, an exhaustive method would be to sort each feature and then use the halfway point between each feature value. In this case there would be O(N*F) candidate splits where N=# data and F= # features. Another way would be to randomly choose K values between the min and max of each feature.

Does anyone know what method is used? Could someone point me to where in the code this occurs?

Contributors should read this: #27159 (comment)

Activity

  1. Snerdify commented on Aug 25, 2023

    @Snerdify

    I'm working on this

  2. Snerdify commented on Aug 26, 2023

    @Snerdify

    @howarth just to be clear , you were unable to find the methods for evaluating candidate splits , correct?

  3. Snerdify commented on Aug 26, 2023

    @Snerdify

    /take

  4. howarth commented on Aug 26, 2023

    @howarth
    Author

    @howarth just to be clear , you were unable to find the methods for evaluating candidate splits , correct?

    @Snerdify I was able to find documentation on the split criterion methods like entropy, gini, etc. What I could not find was documentation on how the set of candidate values is populated for each feature (the set of values for which you compute the split criterion, and then take the max or min). In my initial post I gave two example methods that are commonly used, but I don’t know if either of those are use, or if another is used.

    What I’m actually trying to understand is the computational complexity of creating a single node. To know that I need to know how many splits are calculated at each node.

  5. Snerdify commented on Aug 26, 2023

    @Snerdify

    @howarth got it. Working on it

  6. AyushChauhan-ui commented on Aug 27, 2023

    @AyushChauhan-ui

    @howarth
    Current Approach:
    Scikit-learn's decision tree implementation uses the "best split" strategy as the default approach to identify candidate splits. This means that for each feature, all unique values present in the training data are considered as potential splitting points. The criterion (e.g., Gini impurity or entropy) is computed for each unique value, and the value that maximizes the reduction in impurity is selected as the splitting point for that feature.

    Alternative/Fix:
    If you are interested in an alternative approach for selecting candidate splits, you could consider using the "random split" strategy. In this approach, you randomly choose a subset of candidate values from the feature's range and evaluate the criterion for each of those values. This can significantly reduce the computational complexity, especially for features with a large number of unique values.

    Code Location:
    If you want to delve into the code to understand how candidate splits are identified, you can look into the _splitter.pyx file in scikit-learn's source code. This file contains the core logic for finding the best split in decision trees. Specifically, you can explore the BestSplitter class, where the process of finding the best split point is implemented. You can find this here:
    https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/tree/_splitter.pyx

  7. howarth commented on Aug 28, 2023

    @howarth
    Author

    @AyushChauhan-ui thank you!

  8. Snerdify commented on Aug 29, 2023

    @Snerdify

    @howarth , @AyushChauhan-ui , in the scikit-learn documentation , there is no detailed documentation for gini, variance reduction (which is used for regression trees) , entropy, information gain . Also there is one more splitting method we could add called chi-square splitting method.

  9. Snerdify commented on Aug 29, 2023

    @Snerdify

    Also the complexity that is mentioned is for binary trees and nothing specific about what is the computational complexity for particular decision tree algorithms like CART , ID3. That could be added too.

  10. bmreiniger commented on Sep 2, 2023

    @bmreiniger
    Contributor

    @howarth , @AyushChauhan-ui , in the scikit-learn documentation , there is no detailed documentation for gini, variance reduction (which is used for regression trees) , entropy, information gain .

    https://scikit-learn.org/stable/modules/tree.html#mathematical-formulation

  11. bmreiniger commented on Sep 3, 2023

    @bmreiniger
    Contributor

    [...] for regression, an exhaustive method would be to sort each feature and then use the halfway point between each feature value. In this case there would be O(N*F) candidate splits where N=# data and F= # features. Another way would be to randomly choose K values between the min and max of each feature.

    It's the former. See e.g.

    current_split.threshold = (

    I don't think it's essential to spell this out in the User Guide, but I also don't think it would hurt. There have been some alternatives used, like left or right endpoints instead of midpoints, see e.g. https://datascience.stackexchange.com/q/32638/55122

    Also, uniform selection in the feature range is used, e.g. in IsolationForests.

  12. glemaitre commented on Sep 16, 2023

    @glemaitre
    Member

    Also the complexity that is mentioned is for binary trees and nothing specific about what is the computational complexity for particular decision tree algorithms like CART , ID3. That could be added too.

    Scikit-learn implements CART. This is indeed a decision tree and the complexity for nodes, and tree is specified there: https://scikit-learn.org/stable/modules/tree.html#complexity.

    While complexity is interesting, it will not give you the info about the splitter. Also the original question was something about random forest while here we are speaking decision tree.

    So I see several documentation improvement:

    An important point while modifying the documentation is to keep it as simple as possible and as succinct as possible as well.

  13. 9 remaining items

  14. madhav758 commented on Sep 8, 2025

    @madhav758

    Hi, I’m interested in working on this issue. This would be my first contribution to scikit-learn. Could you please confirm if it’s still open for contribution and assign it to me? Thanks!

  15. balaraj74 commented on Sep 11, 2025

    @balaraj74
  16. VIVEK-MARRI commented on Sep 11, 2025

    @VIVEK-MARRI
  17. Pakhi424 commented on Sep 14, 2025

    @Pakhi424

    Hi, I’m new to open source and would like to contribute to this documentation issue. Could you please assign it to me if possible?

  18. virchan commented on Sep 16, 2025

    @virchan
    Member

    For potential contributors to this issue:

    I strongly recommend reading #27159 (comment) before creating a PR. It explains what changes are required and in which files they should be made.

    Taking the time to read it is definitely worthwhile. Even if you still have questions afterwards, it will help you better frame your confusion so we can assist you or review your PR more effectively.

    Edit: typo

  19. CodeMudit commented on Sep 21, 2025

    @CodeMudit

    Hi @scikit-learn-team!

    First-time contributor here—a first-year CS student learning ML through Kaggle and exploring GSoC 2026. This docs issue looks like a great starter, but I'm a bit confused on the technical details—could someone clarify if it's exhaustive sorting of unique values (O(N*F)) or random selection?

    I'd love to work on this if it's still available. My plan:

    1. Research the split method in _forest.py or _splitter.py.
    2. Add 2-3 sentences to ensemble.rst explaining the approach.
    3. Test docs build and verify.
    4. Reference any related PRs/commits if needed.

    Any guidance on the confusion or code locations would be super helpful! Thanks for the welcoming community—excited to contribute!

    • CodeMudit
  20. lucaEaton commented on Sep 21, 2025

    @lucaEaton

    /take

  21. MBARKI-Omar commented on Sep 23, 2025

    @MBARKI-Omar
  22. removed
    good first issue
    on Sep 23, 2025
  23. ArturoAmorQ commented on Sep 23, 2025

    @ArturoAmorQ
    Member

    FYI I removed the "good first issue" tag as an experiment to see if that reduces the number of bots trying to address it.

  24. ArturoAmorQ commented on Oct 7, 2025

    @ArturoAmorQ
    Member

    I guess its easier if I address this issue. Will submit a PR later today.

  25. self-assigned this
    on Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions