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

[python-package] simplify scikit-learn 1.6+ tags support #6735

Merged
merged 4 commits into from
Dec 4, 2024

Conversation

jameslamb
Copy link
Collaborator

Follow-up to #6718

In that PR, I'd skipped the method resolution order ("MRO") for __sklearn_tags__() in the scikit-learn estimators, to provide compatibility with earlier versions of that library. During development, we switched to having e.g. LGBMClassifier.__sklearn_tags__() raise an AttributeError if run on a too-new version of scikit-learn, making that unnecessary... but never went back to just using inheritance to get __sklearn_tags__().

This fixes that.

Notes for Reviewers

Inspired by dmlc/xgboost#11021 (comment)

tags.estimator_type = "regressor"
tags.regressor_tags = _sklearn_RegressorTags(multi_label=False)
return tags
return super().__sklearn_tags__()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is necessary even though it doesn't do anything, because of this check in scikit-learn:

E TypeError: Estimator LGBMRegressor has defined either _more_tags or _get_tags, but not __sklearn_tags__. If you're customizing tags, and need to support multiple scikit-learn versions, you can implement both __sklearn_tags__ and _more_tags or _get_tags. This change was introduced in scikit-learn=1.6

https://github.com/scikit-learn/scikit-learn/blob/fba028b07ed2b4e52dd3719dad0d990837bde28c/sklearn/utils/estimator_checks.py#L4459-L4465

Added in scikit-learn/scikit-learn#30268

@jameslamb jameslamb changed the title WIP: [python-package] simplify scikit-learn 1.6+ tags support [python-package] simplify scikit-learn 1.6+ tags support Dec 3, 2024
@jameslamb jameslamb marked this pull request as ready for review December 3, 2024 03:20
Copy link
Collaborator

@StrikerRUS StrikerRUS left a comment

Choose a reason for hiding this comment

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

LGTM, except one comment below. Thank you for coming back and simplifying this!

python-package/lightgbm/compat.py Show resolved Hide resolved
@jameslamb jameslamb merged commit 6e0b0a8 into master Dec 4, 2024
48 checks passed
@jameslamb jameslamb deleted the python/simplify-tags branch December 4, 2024 02:05
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.

2 participants