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.
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)?
Most helpful comment
Fixed by removing
link="logit"and wrappingshap.force_plot(float(explainer.expected_value[0]),shap_values[0][0,:], X_test.iloc[0,:], link="logit")`