---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
Cell In[35], line 10
7 # 对于二分类问题,shap_values是长度为2的列表,分别对应类别0和1的SHAP值
8 # 通常关注正类(类别1)的解释:
9 shap_values_positive = shap_values[1]
---> 10 shap.summary_plot(shap_values_positive, X_test, plot_type="bar")
11 shap.force_plot(explainer.expected_value[1], shap_values_positive[0,:], X_test.iloc[0,:])
12 shap.dependence_plot("feature_name", shap_values_positive, X_test)
File d:\python\Lib\site-packages\shap\plots\_beeswarm.py:659, in summary_legacy(shap_values, features, feature_names, max_display, plot_type, color, axis_color, title, alpha, show, sort, color_bar, plot_size, layered_violin_max_num_bins, class_names, class_inds, color_bar_label, cmap, show_values_in_legend, use_log_scale, rng)
654 raise ValueError(
655 shape_msg + " Perhaps the extra column in the shap_values matrix is the "
656 "constant offset? Of so just pass shap_values[:,:-1]."
657 )
658 else:
--> 659 assert num_features == features.shape[1], shape_msg
661 if feature_names is None:
662 feature_names = np.array([labels["FEATURE"] % str(i) for i in range(num_features)])
AssertionError: The shape of the shap_values matrix does not match the shape of the provided data matrix.