TeamHG-Memex / eli5

A library for debugging/inspecting machine learning classifiers and explaining their predictions
http://eli5.readthedocs.io
MIT License
2.75k stars 331 forks source link

KeyError: 'bias' while running show_weights(clf, vec=vec) in xgboost notebook #372

Open SaiAparna1 opened 4 years ago

SaiAparna1 commented 4 years ago

Could anyone please help me to solve following error,

File "C:\anaconda3\lib\site-packages\xgboost\sklearn.py", line 745, in intercept_ return np.array(json.loads(b.get_dump(dump_format='json')[0])['bias'])

KeyError: 'bias'

SusmithBarigidad commented 4 years ago

KeyError : 'bias' is shown when we run the XGBRegressor, please help us on this error

sugarcrm-aorso commented 4 years ago

Seeing the same issue on an XGBClassifier().

danielad-k commented 4 years ago

I have the same issue as well with XGBClassifier.

AshwinB-hat commented 4 years ago

image I just tested the XgbRegressor and could not reproduce the issue. Can one of you paste a screenshot of what you is happening? @SusmithBarigidad @sugarcrm-aorso @danielad-k

supinyu commented 4 years ago

Hi @AshwinB-hat I also meet this error.

Python Version Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 18:10:19) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information.

image

sugarcrm-aorso commented 4 years ago

image I just tested the XgbRegressor and could not reproduce the issue. Can one of you paste a screenshot of what you is happening? @SusmithBarigidad @sugarcrm-aorso @danielad-k

It looks like it may be related to the Classifier while you are referencing the Regressor. Let me know if you need anything more beyond what @supinyu shared.

JulienB-78 commented 4 years ago

The bug is not on eli5 but on xgboost. The call hasattre(xgb, 'intercept_') crashes. This bug is present in the 1.0.2 release and has been fixed by commit Fix checking booster. (#5505). It will be integrated in the 1.1.0 version in preparation (1st release candidate already out).

In the mean time you can easily apply the patch yourself (just one line to change in intercept_(self) of site-packages/xgboost/sklearn.py). Replace getattr(self, 'booster', None) is not None and self.booster not in {gbtree', 'dart'}: by self.get_params()['booster'] not in {'gbtree', 'dart'}:.

supinyu commented 4 years ago

Thank you very much JulienB-78. I update the xgboost version to 1.1.0rc1. The code will not have this error.

sugarcrm-aorso commented 4 years ago

Yup, using the 1.1.0 release candidate worked for me as well. Thanks @JulienB-78