shap.plots.image
- shap.plots.image(shap_values: Explanation | np.ndarray | list[np.ndarray], pixel_values: np.ndarray | None = None, labels: list[str] | np.ndarray | None = None, true_labels: list | None = None, width: int | None = 20, aspect: float | None = 0.2, hspace: float | Literal['auto'] | None = 0.2, labelpad: float | None = None, cmap: str | Colormap | None = <matplotlib.colors.LinearSegmentedColormap object>, vmax: float | None = None, show: bool | None = True)
Plots SHAP values for image inputs.
- Parameters:
- shap_values[numpy.array]
List of arrays of SHAP values. Each array has the shape (# samples x width x height x channels), and the length of the list is equal to the number of model outputs that are being explained.
- pixel_valuesnumpy.array
Matrix of pixel values (# samples x width x height x channels) for each image. It should be the same shape as each array in the
shap_values
list of arrays.- labelslist or np.ndarray
List or
np.ndarray
(# samples x top_k classes) of names for each of the model outputs that are being explained.- true_labels: list
List of a true image labels to plot.
- widthfloat
The width of the produced matplotlib plot.
- labelpadfloat
How much padding to use around the model output labels.
- cmap: str or matplotlib.colors.Colormap
Colormap to use when plotting the SHAP values.
- vmax: Optional float
Sets the colormap scale for SHAP values from
-vmax
to+vmax
.- showbool
Whether
matplotlib.pyplot.show()
is called before returning. Setting this toFalse
allows the plot to be customized further after it has been created.
Examples
See image plot examples.