我正在使用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,:])
异常情况:在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)
但是我遇到了问题:TypeError:ufunc 'isnan'不支持输入类型,并且根据强制转换规则“safe”,无法将输入安全地强制转换为任何支持的类型
有人能指导一下吗?谢谢。
AttributeError: 'list' object has no attribute 'values'
的错误。 - PeJota