我在运行shap.plots.waterfall()时遇到了一个错误,如下所示:
Exception: waterfall_plot requires a scalar base_values of the model output as the first parameter, but you have passed an array as the first parameter! Try shap.waterfall_plot(explainer.base_values[0], values[0], X[0]) or for multi-output models try shap.waterfall_plot(explainer.base_values[0], values[0][0], X[0]).
下面是我的代码:
import shap
explainer = shap.Explainer(model)
shap_values = explainer(X_train)
shap.plots.waterfall(shap_values)我能够让条形图使用下面的代码工作,而不是瀑布函数。shap.summary_plot(shap_values, X_train,feature_names = YE_x.columns.values.tolist(), plot_type="bar")
我非常感谢你的帮助!
发布于 2022-01-20 21:40:46
就像错误说的,而文档
瀑布图的设计是为了显示对单个预测的解释,因此他们期望一个解释对象的一行作为输入。
你可以这样写:
import shap
explainer = shap.Explainer(model)
shap_values = explainer(X_train)
shap.plots.waterfall(shap_values[1]) # or any random valuehttps://stackoverflow.com/questions/70793683
复制相似问题