shap.plots.violin
- shap.plots.violin(shap_values, features=None, feature_names=None, max_display=None, plot_type='violin', color=None, axis_color='#333333', title=None, alpha=1, show=True, sort=True, color_bar=True, plot_size='auto', layered_violin_max_num_bins=20, class_names=None, class_inds=None, color_bar_label='Feature value', cmap=<matplotlib.colors.LinearSegmentedColormap object>, color_bar_label_size=12, color_bar_tick_size=11, axhline_lw=0.5, use_log_scale=False)
Create a SHAP violin plot, colored by feature values when they are provided.
- Parameters:
- shap_valuesExplanation or numpy.ndarray
For single output explanations, this is a matrix of SHAP values (# samples x # features).
- featuresnumpy.ndarray or pandas.DataFrame or list, optional
Matrix of feature values (# samples x # features), or a
feature_nameslist as shorthand.- feature_nameslist, optional
Names of the features (length: # features).
- max_displayint, optional
How many top features to include in the plot (default is 20).
- plot_type{“violin”, “layered_violin”}, optional
What type of summary plot to produce. A “layered_violin” plot shows the distribution of the SHAP values of each variable. A “violin” plot is the same, except with outliers drawn as scatter points.
- colorstr or None, optional
Color or colormap to use for the plot. If None, a default is chosen.
- axis_colorstr, optional
Color for the plot axes.
- titlestr or None, optional
Plot title (currently unused).
- alphafloat, optional
Opacity of the plot elements.
- showbool, optional
Whether
matplotlib.pyplot.show()is called before returning. Setting this toFalseallows the plot to be customized further after it has been created.- sortbool, optional
Whether to sort features by the sum of their effect magnitudes.
- color_barbool, optional
Whether to draw the color bar (legend).
- plot_size{“auto”, float, (float, float), None}, optional
What size to make the plot. By default, the size is auto-scaled based on the number of features that are being displayed. Passing a single float will cause each row to be that many inches high. Passing a pair of floats will scale the plot by that number of inches. If
Noneis passed, then the size of the current figure will be left unchanged.- layered_violin_max_num_binsint, optional
Maximum number of bins for layered violin plots.
- color_bar_labelstr, optional
Label for the color bar.
- cmapstr or Colormap, optional
Colormap to use for coloring points by feature value.
- color_bar_label_sizeint, optional
Font size for the color bar label. Default is 11.
- color_bar_tick_sizeint, optional
Font size for the color bar ticks. Default is 11.
- axhline_lwfloat, optional
Line width for horizontal lines in the plot.
- use_log_scalebool, optional
Whether to use a symmetric log scale for the x-axis.
Examples
See violin plot examples.