shap.plots.bar

shap.plots.bar(shap_values, max_display=10, order=shap.Explanation.abs, clustering=None, clustering_cutoff=0.5, show_data='auto', ax=None, show=True)

Create a bar plot of a set of SHAP values.

Parameters:
shap_valuesshap.Explanation or shap.Cohorts or dictionary of shap.Explanation objects

Passing a multi-row Explanation object creates a global feature importance plot.

Passing a single row of an explanation (i.e. shap_values[0]) creates a local feature importance plot.

Passing a dictionary of Explanation objects will create a multiple-bar plot with one bar type for each of the cohorts represented by the explanation objects.

max_displayint

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

orderOpChain or numpy.ndarray

A function that returns a sort ordering given a matrix of SHAP values and an axis, or a direct sample ordering given as a numpy.ndarray.

By default, take the absolute value.

clustering: np.ndarray or None

A partition tree, as returned by shap.utils.hclust

clustering_cutoff: float

Controls how much of the clustering structure is displayed.

show_data: bool or str

Controls if data values are shown as part of the y tick labels. If “auto”, we show the data only when there are no transforms.

ax: matplotlib Axes

Axes object to draw the plot onto, otherwise uses the current Axes.

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.

Returns:
ax: matplotlib Axes

Returns the Axes object with the plot drawn onto it. Only returned if show=False.

Examples

See bar plot examples.