[英]During handling of the above exception, another exception occurred when using SHAP to interpret keras neural network model
The x_train
looks like this (22 features): x_train
看起来像这样(22 个特征):
total_amount reward difficulty duration discount bogo mobile social web income ... male other_gender age_under25 age_25_to_35 age_35_to_45 age_45_to_55 age_55_to_65 age_65_to_75 age_75_to_85 age_85_to_105
0 0.006311 0.2 0.50 1.000000 1.0 0.0 1.0 1.0 1.0 0.355556 ... 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0
1 0.015595 0.2 0.50 1.000000 1.0 0.0 1.0 1.0 1.0 0.977778 ... 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0
The label is 0
and 1
, it's a binary classification problem, here's the code for building the model, and I was following this page to implement SHAP: label 是0
和1
,这是一个二进制分类问题,这是构建 model 的代码,我正在关注这个页面来实现 SHAP:
#use SHAG
deep_explainer = shap.DeepExplainer(nn_model_2, x_train[:100])
# explain the first 10 predictions
# explaining each prediction requires 2 * background dataset size runs
shap_values = deep_explainer.shap_values(x_train)
This gave me error:这给了我错误:
KeyError: 0
During handling of the above exception, another exception occurred
I have no idea what this message is complaining, I tried to use SHAP with a XGBoost and Logistic Regression model and they both work fine, I'm new to keras and SHAP, can someone have a look for me and how I can solved it?我不知道这条消息在抱怨什么,我尝试将 SHAP 与 XGBoost 和逻辑回归 model 一起使用,它们都工作正常,我是 keras 和 SHAP 的新手,有人可以看看我以及我如何解决它? Many thanks.非常感谢。
I think SHAP
(whatever it is) is expecting a Numpy array and so indexing x_train
like a Numpy array, it yields an error.我认为SHAP
(无论它是什么)期待一个 Numpy 数组,因此像 Numpy 数组一样索引x_train
,它会产生错误。 Try:尝试:
shap_values = deep_explainer.shap_values(x_train.values)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.