Skip to content

XGBoost 1.02 does not work with scikit-learn==0.23 #17227

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

Closed
marov opened this issue May 14, 2020 · 2 comments
Closed

XGBoost 1.02 does not work with scikit-learn==0.23 #17227

marov opened this issue May 14, 2020 · 2 comments
Milestone

Comments

@marov
Copy link

marov commented May 14, 2020

Describe the bug

xgboost.XGBClassifier() throws an error

Steps/Code to Reproduce

pip install scikit-learn==0.23
pip install xgboost==1.0.2

python
>>> import xgboost
>>> xgboost.XGBClassifier()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.7/site-packages/sklearn/base.py", line 279, in __repr__
    repr_ = pp.pformat(self)
  File "/opt/conda/lib/python3.7/pprint.py", line 144, in pformat
    self._format(object, sio, 0, 0, {}, 0)
  File "/opt/conda/lib/python3.7/pprint.py", line 161, in _format
    rep = self._repr(object, context, level)
  File "/opt/conda/lib/python3.7/pprint.py", line 393, in _repr
    self._depth, level)
  File "/opt/conda/lib/python3.7/site-packages/sklearn/utils/_pprint.py", line 170, in format
    changed_only=self._changed_only)
  File "/opt/conda/lib/python3.7/site-packages/sklearn/utils/_pprint.py", line 414, in _safe_repr
    params = _changed_params(object)
  File "/opt/conda/lib/python3.7/site-packages/sklearn/utils/_pprint.py", line 98, in _changed_params
    if (repr(v) != repr(init_params[k]) and
KeyError: 'base_score'
@TomDLT
Copy link
Member

TomDLT commented May 15, 2020

This is because XGBClassifier uses kwargs, while scikit-learn's pretty print assumes that all parameters are explicitly defined in the __init__.py.
(from the doc):

The arguments accepted by __init__ should all be keyword arguments with a default value.

We should fix sklearn.utils._pprint._changed_params to be more tolerant to estimators not complying with this rule, e.g. keeping all parameters that are not explicitly defined in the __init__.

    for k, v in params.items():
        if k not in init_params or (
                repr(v) != repr(init_params[k])
                and not (is_scalar_nan(init_params[k]) and is_scalar_nan(v))):
            filtered_params[k] = v

@TomDLT TomDLT added this to the 0.23.1 milestone May 15, 2020
@TomDLT
Copy link
Member

TomDLT commented May 15, 2020

Actually it has already been fixed in #17205.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants