Skip to content

Adapt to scikit-learn 1.6 estimator tag changes #11021

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

Merged
merged 15 commits into from
Dec 4, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement __sklearn_tags__()
  • Loading branch information
jameslamb committed Nov 24, 2024
commit 3106cf10e8ef9668c36fbdf4bd7c0d54270c5a80
23 changes: 22 additions & 1 deletion python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
from .data import _is_cudf_df, _is_cudf_ser, _is_cupy_alike, _is_pandas_df
from .training import train

# TODO: put in compat.py
from sklearn.utils import (
ClassifierTags as _sklearn_ClassifierTags,
RegressorTags as _sklearn_RegressorTags
)

class XGBRankerMixIn: # pylint: disable=too-few-public-methods
"""MixIn for ranking, defines the _estimator_type usually defined in scikit-learn
Expand Down Expand Up @@ -1535,6 +1540,13 @@ def _more_tags(self) -> Dict[str, bool]:
tags["multilabel"] = True
return tags

def __sklearn_tags__(self) -> "_sklearn_Tags":
tags = XGBModel.__sklearn_tags__(self)
tags.estimator_type = "classifier"
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this if we inherit the classifier mixin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah you are totally right, I don't think we do:

https://github.com/scikit-learn/scikit-learn/blob/e6037ba412ed889a888a60bd6c022990f2669507/sklearn/base.py#L536-L544

Removed this, the corresponding LGBRegressor code, and the imports of ClassifierTags / RegressorTags in a511848

# TODO: get this information from self._more_tags()
tags.classifier_tags = _sklearn_ClassifierTags(multi_label=True)
return tags

@_deprecate_positional_args
def fit(
self,
Expand Down Expand Up @@ -1821,6 +1833,15 @@ def _more_tags(self) -> Dict[str, bool]:
tags["multioutput_only"] = False
return tags

def __sklearn_tags__(self) -> "_sklearn_Tags":
tags = XGBModel.__sklearn_tags__(self)
tags.estimator_type = "regressor"
tags.regressor_tags = _sklearn_RegressorTags()
# TODO: get this information from self._more_tags()
tags.target_tags.multi_output = True
tags.target_tags.single_output = False
return tags


@xgboost_model_doc(
"scikit-learn API for XGBoost random forest regression.",
Expand All @@ -1847,7 +1868,7 @@ def __init__(
subsample=subsample,
colsample_bynode=colsample_bynode,
reg_lambda=reg_lambda,
**kwargs,
**kwargs,g
)
_check_rf_callback(self.early_stopping_rounds, self.callbacks)

Expand Down