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
regressor tests passing
  • Loading branch information
jameslamb committed Nov 24, 2024
commit 3af44bed3d3c576aabd882f383adfa457d845208
22 changes: 18 additions & 4 deletions python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,22 @@ def get_params(self, deep: bool = True) -> Dict[str, Any]:
# 2. Return whatever in `**kwargs`.
# 3. Merge them.
params = super().get_params(deep)
# [DEBUG] this only contains {'objective': 'reg:squarederror'}
#raise RuntimeError(params)
# XGBRegressor -> XGBModel -> BaseEstimator
# XGBModel -> BaseEstimator
cp = copy.copy(self)
cp.__class__ = cp.__class__.__bases__[0]
# [DEBUG] this points to <class 'xgboost.sklearn.XGBRegressor'>
# raise RuntimeError(cp.__class__)
# [DEBUG] this is (<class 'sklearn.base.RegressorMixin'>, <class 'xgboost.sklearn.XGBModel'>)
#raise RuntimeError(cp.__class__.__bases__)
# TODO: make this less fragile
if len(cp.__class__.__bases__) == 1:
cp.__class__ = cp.__class__.__bases__[0]
else:
cp.__class__ = cp.__class__.__bases__[1]
# [DEBUG] this is finding RegressorMixin rn
#raise RuntimeError(cp.__class__)
params.update(cp.__class__.get_params(cp, deep))
# if kwargs is a dict, update params accordingly
if hasattr(self, "kwargs") and isinstance(self.kwargs, dict):
Expand Down Expand Up @@ -1819,7 +1833,7 @@ def fit(
"Implementation of the scikit-learn API for XGBoost regression.",
["estimators", "model", "objective"],
)
class XGBRegressor(XGBModel, XGBRegressorBase):
class XGBRegressor(XGBRegressorBase, XGBModel):
# pylint: disable=missing-docstring
@_deprecate_positional_args
def __init__(
Expand All @@ -1839,7 +1853,7 @@ def __sklearn_tags__(self) -> "_sklearn_Tags":
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
tags.target_tags.single_output = True
return tags


Expand Down Expand Up @@ -1868,7 +1882,7 @@ def __init__(
subsample=subsample,
colsample_bynode=colsample_bynode,
reg_lambda=reg_lambda,
**kwargs,g
**kwargs,
)
_check_rf_callback(self.early_stopping_rounds, self.callbacks)

Expand Down