Shap: Regression Ensembles (XGB, GBT) ValueError: Input contains NaN, infinity or a value too large for dtype('float64').

Created on 27 Aug 2019  路  2Comments  路  Source: slundberg/shap

Hi,

Shap version: shap-0.29.3

Whenever I try to use KernelExplainer with Sklearn API of XGB, GradientBoostedRegressor or VotingRegressor I get a value error. None of the datasets contain inf's or NaN's.

ValueError: Input contains NaN, infinity or a value too large for dtype('float64').

Minimum example:

import sklearn
import shap
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_boston
shap.initjs()
X_train,X_test,Y_train,Y_test = train_test_split(*load_boston(return_X_y=True), test_size=0.2, random_state=0)
gb = sklearn.ensemble.GradientBoostingRegressor()
gb.fit(X_train, Y_train)
explainer = shap.KernelExplainer(gb.predict, X_train, link="logit")
shap_values = explainer.shap_values(X_test, nsamples=100)
shap.force_plot(explainer.expected_value[0], shap_values[0][0,:], X_test.iloc[0,:], link="logit")

Any help would be appreciated.

Most helpful comment

Fixed by removing link="logit" and wrapping shap.force_plot(float(explainer.expected_value[0]), shap_values[0][0,:], X_test.iloc[0,:], link="logit")`

All 2 comments

Fixed by removing link="logit" and wrapping shap.force_plot(float(explainer.expected_value[0]), shap_values[0][0,:], X_test.iloc[0,:], link="logit")`

@naefl Thanks so much for a working solution - would it help if shap threw a more helpful error message (since in our cases the input doesn't contain NaN, infinity etc. as stated in the error message)?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

artemmavrin picture artemmavrin  路  4Comments

GitAnalyst picture GitAnalyst  路  3Comments

samupino picture samupino  路  3Comments

gabrielcs picture gabrielcs  路  3Comments

cbeauhilton picture cbeauhilton  路  3Comments