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

Random Forest classifier does not work correctly with scikit >= 1.4.1 #61

Open
vkozmik opened this issue Nov 8, 2024 · 2 comments
Open

Comments

@vkozmik
Copy link

vkozmik commented Nov 8, 2024

Connected with the change in scikit, I think that the values of "votes" should be divided by "node_count"
API Change The tree_.value attribute in tree.DecisionTreeClassifier, tree.DecisionTreeRegressor, tree.ExtraTreeClassifier and tree.ExtraTreeRegressor changed from an weighted absolute count of number of samples to a weighted fraction of the total number of samples. #27639 by Samuel Ronsin.

Suggest to change line 276 of tree.py:

Originally:
votes = [[[float(votes_for(c).get('recordCount')) if votes_for(c) is not None else 0.0 for c in classes]]]

Suggested:
votes = [[[float(votes_for(c).get('recordCount')) / node_count if votes_for(c) is not None else 0.0 for c in classes]]]

@iamDecode
Copy link
Owner

Great, thanks for figuring this out! I would have to check if changing it to a weighted fraction is still compatible with older versions of scikit-learn.

@vkozmik
Copy link
Author

vkozmik commented Nov 11, 2024

You're welcome. Alternatively, we can wrap the new code in some condition for scikit version

major, minor, patch = map(int, sklearn.version.split("."))
if major <= 1 and (minor <= 3 or (major == 4 and patch ==0)):
old code
else
new code

not nice, but probably solves the issue

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

No branches or pull requests

2 participants