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

Fix filtering callable objects in skl xgb param. #6466

Merged
merged 2 commits into from Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion python-package/xgboost/sklearn.py
Expand Up @@ -398,7 +398,7 @@ def get_xgb_params(self):
'importance_type', 'kwargs', 'missing', 'n_estimators', 'use_label_encoder'}
filtered = dict()
for k, v in params.items():
if k not in wrapper_specific:
if k not in wrapper_specific and not callable(v):
filtered[k] = v
return filtered

Expand Down
15 changes: 15 additions & 0 deletions tests/python/test_with_sklearn.py
Expand Up @@ -399,6 +399,21 @@ def dummy_objective(y_true, y_preds):
X, y
)

cls = xgb.XGBClassifier(use_label_encoder=False, n_estimators=1)
cls.fit(X, y)

is_called = [False]

def wrapped(y, p):
is_called[0] = True
return logregobj(y, p)

cls.set_params(objective=wrapped)
cls.predict(X) # no throw
cls.fit(X, y)

assert is_called[0]


def test_sklearn_api():
from sklearn.datasets import load_iris
Expand Down