Xgboost: KeyError: 'base_score'

Created on 15 May 2020  Â·  8Comments  Â·  Source: dmlc/xgboost

I just upgraded to the new version of scikit-learn (0.23.0) on my Mac, and I just started getting this error:

>>> from xgboost import XGBClassifier
>>> model = XGBClassifier()
>>> model
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/base.py", line 279, in __repr__
    repr_ = pp.pformat(self)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pprint.py", line 144, in pformat
    self._format(object, sio, 0, 0, {}, 0)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pprint.py", line 161, in _format
    rep = self._repr(object, context, level)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pprint.py", line 393, in _repr
    self._depth, level)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/utils/_pprint.py", line 170, in format
    changed_only=self._changed_only)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/sklearn/utils/_pprint.py", line 414, in _safe_repr
    params = _changed_params(object)
  File "/Library/Frameworks/Python.framework/Versions/3.7/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'
>>> 

I can confirm that the implicit print works fine when I revert to scikit-learn version 0.22.2.post1.

Most helpful comment

I just faced with the same issue and updated sklearn to 0.23.1 fixed this issue.

All 8 comments

Em ... The get_params from scikit learn is dart magic.

I believe it's fixed in upstream sklearn. Checked with master branch of scikit learn.

Great, just curious which commit to sklearn master solves the issue?

On Fri, May 15, 2020, 2:56 AM Jiaming Yuan notifications@github.com wrote:

Closed #5668 https://github.com/dmlc/xgboost/issues/5668.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/dmlc/xgboost/issues/5668#event-3339612150, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/ADT3JUJQGEYWLM3LBGM2DKTRRTRSZANCNFSM4NBIEUJA
.

Not sure, I have only bisected to find which commit caused it.

Looks like it has been discussed here: https://github.com/scikit-learn/scikit-learn/issues/17227

Hey...So my model trains even after this error? Is that correct training.
Also if somebody could tell me what's the exact fix as I went through all the links but couldn't find a solution?

It throws an error only if you print the model. Other parts like training are not related.

The fix: Compile latest scikit learn, or use scikit learn 0.22, or wait for scikit learn 0.24.

I just faced with the same issue and updated sklearn to 0.23.1 fixed this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

frankzhangrui picture frankzhangrui  Â·  3Comments

pplonski picture pplonski  Â·  3Comments

uasthana15 picture uasthana15  Â·  4Comments

matthewmav picture matthewmav  Â·  3Comments

yananchen1989 picture yananchen1989  Â·  3Comments