Skip to content

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!

@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
@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants