Skip to content

Conversation

@hcho3
Copy link
Collaborator

@hcho3 hcho3 commented Feb 5, 2025

No description provided.

@hcho3 hcho3 mentioned this pull request Feb 5, 2025
5 tasks
@hcho3 hcho3 force-pushed the backport_sklearn_fix branch 2 times, most recently from 63198cf to fb45506 Compare February 5, 2025 21:02
@hcho3 hcho3 force-pushed the backport_sklearn_fix branch from fb45506 to c616e14 Compare February 5, 2025 21:53
@hcho3
Copy link
Collaborator Author

hcho3 commented Feb 5, 2025

Just tried the following snippet:

from sklearn.model_selection import GridSearchCV
from sklearn.datasets import load_breast_cancer
from xgboost import XGBClassifier

X, y = load_breast_cancer(return_X_y=True)

param_grid = {"learning_rate": [0.1, 0.2]}
xgb = XGBClassifier(objective='binary:logistic')
clf = GridSearchCV(xgb, param_grid, scoring='accuracy', cv=5, verbose=1)
clf.fit(X, y)

Before this patch:

$ python test.py
Traceback (most recent call last):
  File "/home/ubuntu/xgboost/test.py", line 10, in <module>
    clf.fit(X, y)
  File "/home/ubuntu/miniforge3/envs/foobar/lib/python3.10/site-packages/sklearn/base.py", line 1389, in wrapper
    return fit_method(estimator, *args, **kwargs)
  File "/home/ubuntu/miniforge3/envs/foobar/lib/python3.10/site-packages/sklearn/model_selection/_search.py", line 933, in fit
    cv_orig = check_cv(self.cv, y, classifier=is_classifier(estimator))
  File "/home/ubuntu/miniforge3/envs/foobar/lib/python3.10/site-packages/sklearn/base.py", line 1237, in is_classifier
    return get_tags(estimator).estimator_type == "classifier"
  File "/home/ubuntu/miniforge3/envs/foobar/lib/python3.10/site-packages/sklearn/utils/_tags.py", line 430, in get_tags
    sklearn_tags_provider[klass] = klass.__sklearn_tags__(estimator)  # type: ignore[attr-defined]
  File "/home/ubuntu/miniforge3/envs/foobar/lib/python3.10/site-packages/sklearn/base.py", line 540, in __sklearn_tags__
    tags = super().__sklearn_tags__()
AttributeError: 'super' object has no attribute '__sklearn_tags__'

After this patch:

$ python test.py
Fitting 5 folds for each of 2 candidates, totalling 10 fits

@hcho3 hcho3 requested review from trivialfis and removed request for trivialfis February 5, 2025 22:20
@hcho3 hcho3 merged commit b8cfb56 into dmlc:release_2.1.0 Feb 5, 2025
26 of 29 checks passed
@hcho3 hcho3 deleted the backport_sklearn_fix branch February 5, 2025 23:37
@jakirkham
Copy link
Contributor

Huzzah! 🥳

Thanks Hyunsu 🙏

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.

4 participants