小编bho*_*sad的帖子

SHAP 异常:TreeExplainer 中的可加性检查失败

我试图为本地解释的单行创建形状值,但我一直收到此错误。我尝试了各种方法但仍然无法修复它们。

到目前为止我所做的事情 -

创建了随机决策树模型 -

from sklearn.ensemble import ExtraTreesRegressor
extra_tree = ExtraTreesRegressor(random_state=42)
extra_tree.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)

然后尝试计算形状值 -

# create a explainer object
explainer = shap.Explainer(extra_tree)    
explainer.expected_value
array([15981.25812347])

#calculate shap value for a single row
shap_values = explainer.shap_values(pd.DataFrame(X_train.iloc[9274]).T)
Run Code Online (Sandbox Code Playgroud)

这给了我这个错误 -

Exception: Additivity check failed in TreeExplainer! Please ensure the data matrix you passed to the explainer is the same shape that the model was trained on. If your data shape is correct then please report this on GitHub. Consider retrying with the …
Run Code Online (Sandbox Code Playgroud)

python machine-learning shap

5
推荐指数
1
解决办法
9723
查看次数

标签 统计

machine-learning ×1

python ×1

shap ×1