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>, auto_size_plot=None, use_log_scale=False)

Create a SHAP violin plot, colored by feature values when they are provided.

Parameters:
shap_valuesExplanation, or numpy.array

For single output explanations, this is a matrix of SHAP values (# samples x # features).

featuresnumpy.array or pandas.DataFrame or list

Matrix of feature values (# samples x # features) or a feature_names list as shorthand.

feature_nameslist

Names of the features (length: # features).

max_displayint

How many top features to include in the plot (default is 20).

plot_type“violin”, or “layered_violin”.

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.

color_barbool

Whether to draw the color bar (legend).

showbool

Whether matplotlib.pyplot.show() is called before returning. Setting this to False allows the plot to be customized further after it has been created.

plot_size“auto” (default), float, (float, float), or None

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 None is passed, then the size of the current figure will be left unchanged.

Examples

See violin plot examples.