gpt4 book ai didi

decision-tree - shap.force_plot() 引发异常 : In v0. 20 force_plot 现在需要基值作为第一个参数

转载 作者:行者123 更新时间:2023-12-04 12:00:57 25 4
gpt4 key购买 nike

我正在使用 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)

然后我执行以下操作并引发异常:
shap.initjs()
shap.force_plot(shap_values[0,:-1], X.iloc[0,:])

异常(exception):在 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)

我阅读了文档,但无法理解解释器。我试过:
explainer = shap.TreeExplainer(model,data=pool1)
#Also tried:
explainer = shap.TreeExplainer(model,data=X)

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

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

最佳答案

我遇到了与下面相同的错误-

Exception: In v0.20 force_plot now requires the base value as the first parameter! Try shap.force_plot(explainer.expected_value, shap_values) or for multi-output models try shap.force_plot(explainer.expected_value[0], shap_values[0]).



这帮助我解决了问题-
import shap
explainer = shap.TreeExplainer(model,data=X)
shap.initjs()
shap.force_plot(explainer.expected_value[0],X.iloc[0,:])

同样对于以下问题 -

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''



检查您的数据,如果它包含任何 NaN 或缺失值。
希望这可以帮助!

关于decision-tree - shap.force_plot() 引发异常 : In v0. 20 force_plot 现在需要基值作为第一个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56791085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com