MNT: Trees - Clean-up behaviors around splitter - #33150
Conversation
AnneBeyer
left a comment
There was a problem hiding this comment.
Looks reasonable to me.
._fit._fit
._fit._fit
._fitsplitter
AnneBeyer
left a comment
There was a problem hiding this comment.
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?
| is_classifier, | ||
| ) | ||
| from sklearn.tree import _criterion, _splitter | ||
| from sklearn.tree import _criterion, _splitter # type: ignore[attr-defined] |
There was a problem hiding this comment.
Just a question: why is this needed now?
There was a problem hiding this comment.
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.
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. |
| :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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yes, this is much clearer now, thank you!
I stumbled on that while experimenting some things on trees.
Reference Issues/PRs
RFC #33158
What does this implement/fix? Explain your changes.
splitterparameter (and henceself.splitter) can never be aSplitterinstance, because of the parameter constraint:"splitter": [StrOptions({"best", "random"})]. So I removed the branch checking for that.DecisionTree*/ExtraTree*: why accepting asplitterparameter? (let's deprecate it) #33158ExtraTree*andDecisionTree*are the exact same model (only with different defaults)=> they should not have different behaviors regarding
__sklearn_tags__=> I removed
__sklearn_tags__definition fromExtraTree*(so they inherit it fromDecisionTree*)AI usage: no
Any other comments?
I think this could help a bit in potential future changes I envision for trees (long term).