Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce max_val parameter in image plot #2848

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions shap/plots/_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def image(shap_values: Explanation or np.ndarray,
hspace: Optional[float] = 0.2,
labelpad: Optional[float] = None,
cmap: Optional[str or Colormap] = colors.red_transparent_blue,
show: Optional[bool] = True):
show: Optional[bool] = True,
max_val: Optiona[float] = None
):
"""Plots SHAP values for image inputs.

Parameters
Expand Down Expand Up @@ -157,7 +159,10 @@ def image(shap_values: Explanation or np.ndarray,
abs_vals = np.stack([np.abs(shap_values[i]) for i in range(len(shap_values))], 0).flatten()
else:
abs_vals = np.stack([np.abs(shap_values[i].sum(-1)) for i in range(len(shap_values))], 0).flatten()
max_val = np.nanpercentile(abs_vals, 99.9)

if max_val is None:
max_val = np.nanpercentile(abs_vals, 99.9)

for i in range(len(shap_values)):
if labels is not None:
axes[row, i + 1].set_title(labels[row, i], **label_kwargs)
Expand Down