[英]During handling of the above exception, another exception occurred when using SHAP to interpret keras neural network model
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
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)
這給了我錯誤:
KeyError: 0
During handling of the above exception, another exception occurred
我不知道這條消息在抱怨什么,我嘗試將 SHAP 與 XGBoost 和邏輯回歸 model 一起使用,它們都工作正常,我是 keras 和 SHAP 的新手,有人可以看看我以及我如何解決它? 非常感謝。
我認為SHAP
(無論它是什么)期待一個 Numpy 數組,因此像 Numpy 數組一樣索引x_train
,它會產生錯誤。 嘗試:
shap_values = deep_explainer.shap_values(x_train.values)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.