Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT: Trees - Clean-up behaviors around splitter - #33150

Merged
lorentzenchr merged 11 commits into
scikit-learn:mainfrom
cakedev0:mnt/tree/remove_splitter_branch
Jun 10, 2026
Merged

MNT: Trees - Clean-up behaviors around splitter #33150
lorentzenchr merged 11 commits into
scikit-learn:mainfrom
cakedev0:mnt/tree/remove_splitter_branch

Conversation

@cakedev0

@cakedev0 cakedev0 commented Jan 28, 2026

Copy link
Copy Markdown
Contributor

I stumbled on that while experimenting some things on trees.

Reference Issues/PRs

RFC #33158

What does this implement/fix? Explain your changes.

  • The splitter parameter (and hence self.splitter) can never be a Splitter instance, because of the parameter constraint: "splitter": [StrOptions({"best", "random"})]. So I removed the branch checking for that.
  • As stated in RFC: DecisionTree*/ExtraTree*: why accepting a splitter parameter? (let's deprecate it) #33158 ExtraTree* and DecisionTree* are the exact same model (only with different defaults)
    => they should not have different behaviors regarding __sklearn_tags__
    => I removed __sklearn_tags__ definition from ExtraTree* (so they inherit it from DecisionTree*)

AI usage: no

Any other comments?

I think this could help a bit in potential future changes I envision for trees (long term).

@cakedev0
cakedev0 marked this pull request as ready for review January 28, 2026 21:41

@AnneBeyer AnneBeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks reasonable to me.

Comment thread sklearn/tree/_classes.py Outdated
@cakedev0 cakedev0 changed the title MNT: Trees - Remove unreachable branch in ._fit [paused] MNT: Trees - Remove unreachable branch in ._fit Jan 30, 2026
@cakedev0
cakedev0 marked this pull request as draft January 30, 2026 09:27
@github-actions github-actions Bot added the CI:Linter failure The linter CI is failing on this PR label May 22, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label May 22, 2026
@cakedev0 cakedev0 changed the title [paused] MNT: Trees - Remove unreachable branch in ._fit MNT: Trees - Remove unreachable branch in ._fit May 22, 2026
@cakedev0 cakedev0 changed the title MNT: Trees - Remove unreachable branch in ._fit MNT: Trees - Clean-up behaviors around splitter May 22, 2026
@cakedev0
cakedev0 requested a review from AnneBeyer May 22, 2026 15:54
@cakedev0
cakedev0 marked this pull request as ready for review May 22, 2026 15:54
@cakedev0 cakedev0 added this to Labs May 25, 2026
@cakedev0 cakedev0 moved this to Blocked in Labs May 25, 2026

@AnneBeyer AnneBeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Still LGTM, thanks @cakedev0!

I didn't follow the discussion too closely, but has this comment been addressed anywhere? I saw @betatim's comment on not wanting to add more content to the docstrings, but since it seemed to be causing quite some confusion, should we at least link to an example comparing both versions (or create it, if it doesn't exist) from the class docstrings?

Comment thread sklearn/tree/_classes.py
is_classifier,
)
from sklearn.tree import _criterion, _splitter
from sklearn.tree import _criterion, _splitter # type: ignore[attr-defined]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a question: why is this needed now?

@cakedev0 cakedev0 Jun 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This needed is after removing from sklearn.tree._splitter import Splitter: it seems that without this line, mypy considers sklearn.tree._splitter doesn't exist.

@cakedev0

cakedev0 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

I didn't follow the discussion too closely, but has #33158 (comment) been addressed anywhere?

No, I'm still not sure what's the best decision here (remove class vs remove param vs add doc). Feel free to give an opinion, having more opinions there would be helpful I think.

@cakedev0

cakedev0 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@AnneBeyer

I noticed this user-guide was inaccurate about support of missing values in trees. It was already inaccurate before this PR, but even more after this PR so this is a good place to fix it I think: 6c98787

I also slightly rephrased a related paragraph: d2556bd let me know what you think.

@cakedev0
cakedev0 requested a review from AnneBeyer June 2, 2026 09:28
Comment thread doc/modules/tree.rst Outdated
:class:`ExtraTreeClassifier`, and :class:`ExtraTreeRegressor` (``splitter='random'``)
handle missing values in a slightly different way. When splitting a node, a random
threshold will be chosen to split the non-missing values on, while the missing values
are all randomly assigned to one side or the other. This is repeated for every

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe it is just me, but I think this could still be read ambiguously as "all missing values going to the same (randomly selected) node", or "all missing values being randomly distributed between both nodes" (and having read this section and the one above too many times, I'm confused now which one it actually is 😅). Before I go digging in the code now, maybe you can clarify?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My main goal was to make this clear, so thanks for the feedback. Is it better now?

...while the missing values are assigned together to one randomly chosen side.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, this is much clearer now, thank you!

@lorentzenchr
lorentzenchr merged commit 654a9bb into scikit-learn:main Jun 10, 2026
38 checks passed
@github-project-automation github-project-automation Bot moved this from Blocked to Done in Labs Jun 10, 2026
prady0t pushed a commit to prady0t/scikit-learn that referenced this pull request Sep 2, 2026
@jeremiedbb jeremiedbb mentioned this pull request Sep 8, 2026
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants