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

Select between ._fit() of .fit() depending on the sklearn version used #16

Merged
merged 5 commits into from
Jan 22, 2024

Conversation

lccatala
Copy link

@lccatala lccatala commented Jan 17, 2024

Fixes #15

Scikit-learn changed their API between versions 1.2.2 and 1.3.0, replacing BaseDecisionTree.fit() with BaseDecisionTree._fit().

I check the sklearn.version field before calling one or the other.

# (1) Build the initial tree as usual
super(M5Base, self).fit(X, y, sample_weight=sample_weight, check_input=check_input)
fit_method = getattr(super(M5Base, self), fit_method_name)
Copy link
Owner

Choose a reason for hiding this comment

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

Nitpick: readability: please move all new lines after the comment, or all lines before the comment.

@smarie
Copy link
Owner

smarie commented Jan 20, 2024

Thanks @lccatala !

Although your code does the trick, it would probably be more readable/maintainable to rely on Version. I suggest that you add the two following constants at the top of the file instead :

from packaging.version import Version

SKLEARN_VERSION = Version(sklearn.__version__)
SKLEARN13_OR_GREATER = SKLEARN_VERSION >= Version("1.3.0")

Then you can use SKLEARN13_OR_GREATER in your if test in place of the variable you had created from the version tuple

Thanks !

@smarie
Copy link
Owner

smarie commented Jan 20, 2024

Also, can you please add a new changelog section 0.3.2 - Fixed compliance with sklearn 1.3.0 containing a single entry with your contribution ? Please look at the previous entries for an example.
Thanks again !

@lccatala
Copy link
Author

from packaging.version import Version

SKLEARN_VERSION = Version(sklearn.__version__)
SKLEARN13_OR_GREATER = SKLEARN_VERSION >= Version("1.3.0")

Didn't know that existed, thanks!

src/m5py/main.py Outdated Show resolved Hide resolved
src/m5py/main.py Outdated Show resolved Hide resolved
@smarie smarie merged commit 927bed8 into smarie:main Jan 22, 2024
6 checks passed
@smarie
Copy link
Owner

smarie commented Jan 22, 2024

All set, thanks @lccatala ! Release 0.3.2 should be available in a few minutes

@smarie
Copy link
Owner

smarie commented Jan 22, 2024

Release is now available. Thanks a lot !

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

Successfully merging this pull request may close these issues.

Can't run examples because lack of .fit() method
2 participants