小编Fra*_*lin的帖子

shap.force_plot() 引发例外:在 v0.20 force_plot 现在需要基值作为第一个参数

我正在使用 Catboost 并希望可视化 shap_values:

from catboost import CatBoostClassifier
model = CatBoostClassifier(iterations=300)
model.fit(X, y,cat_features=cat_features)

pool1 = Pool(data=X, label=y, cat_features=cat_features)
shap_values = model.get_feature_importance(data=pool1, fstr_type='ShapValues', verbose=10000)

shap_values.shape
Output: (32769, 10)
X.shape
Output: (32769, 9)
Run Code Online (Sandbox Code Playgroud)

然后我执行以下操作并引发异常:

shap.initjs()
shap.force_plot(shap_values[0,:-1], X.iloc[0,:])
Run Code Online (Sandbox Code Playgroud)

例外:在 v0.20 force_plot 现在需要基值作为第一个参数!尝试 shap.force_plot(explainer.expected_value, shap_values) 或对于多输出模型尝试 shap.force_plot(explainer.expected_value[0], shap_values[0])。

以下工作,但我想让 force_plot() 工作:

shap.initjs()
shap.summary_plot(shap_values[:,:-1], X)
Run Code Online (Sandbox Code Playgroud)

我阅读了文档,但无法理解解释器。我试过:

explainer = shap.TreeExplainer(model,data=pool1)
#Also tried:
explainer = shap.TreeExplainer(model,data=X)
Run Code Online (Sandbox Code Playgroud)

但我得到:TypeError: ufunc 'isnan' 不支持输入类型,并且根据转换规则 ''safe'' 无法将输入安全地强制转换为任何支持的类型

任何人都可以指出我正确的方向吗?谢谢

decision-tree xgboost lightgbm catboost

6
推荐指数
1
解决办法
2392
查看次数

标签 统计

catboost ×1

decision-tree ×1

lightgbm ×1

xgboost ×1