Usual plots¶
The shap.plots-equivalent figures. Each function accepts SHAP values as an
Explanation-like object, a NumPy array, or a pandas DataFrame, plus an optional typed
config (see Configuration).
bar ¶
Global feature-importance bar plot (shap.plots.bar equivalent).
bar ¶
bar(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: BarConfig | None = None,
) -> Figure
Render a feature-importance bar plot as a Plotly figure.
For a multi-sample explanation, bars encode the mean absolute SHAP value
per feature. For a single instance, bars encode the signed contributions
and are colored red (positive) or blue (negative), matching shap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
base_values
|
object
|
Forwarded to :func: |
None
|
data
|
object
|
Forwarded to :func: |
None
|
feature_names
|
object
|
Forwarded to :func: |
None
|
output_index
|
object
|
Forwarded to :func: |
None
|
config
|
BarConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The bar figure. |
Source code in src/shaply/plots/usual/bar.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
beeswarm ¶
Beeswarm summary plot (shap.plots.beeswarm equivalent).
beeswarm ¶
beeswarm(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: BeeswarmConfig | None = None,
) -> Figure
Render a beeswarm summary plot as a Plotly figure.
Each point is one sample's SHAP value for a feature, spread vertically by local density and colored by the (normalized) feature value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
base_values
|
object
|
Forwarded to :func: |
None
|
data
|
object
|
Forwarded to :func: |
None
|
feature_names
|
object
|
Forwarded to :func: |
None
|
output_index
|
object
|
Forwarded to :func: |
None
|
config
|
BeeswarmConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The beeswarm figure. |
Source code in src/shaply/plots/usual/beeswarm.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
beeswarm_scatter ¶
beeswarm_scatter(
explanation: Explanation,
order: IntArray,
color_scale: ColorScale,
*,
point_size: float,
opacity: float,
jitter: float,
show_colorbar: bool = True,
) -> Scatter
Build the beeswarm scatter trace for features given in display order.
order lists feature indices bottom-to-top; each feature's samples are
plotted at y = row (+ density offset) with x the SHAP value and the
color encoding the (normalized) feature value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
explanation
|
Explanation
|
The explanation to render. |
required |
order
|
IntArray
|
Feature indices in display order (bottom row first). |
required |
color_scale
|
ColorScale
|
Color scale encoding feature values. |
required |
point_size
|
float
|
Marker size, marker opacity and vertical density spread. |
required |
opacity
|
float
|
Marker size, marker opacity and vertical density spread. |
required |
jitter
|
float
|
Marker size, marker opacity and vertical density spread. |
required |
show_colorbar
|
bool
|
Whether to attach the shared Low/High colorbar to the trace. |
True
|
Returns:
| Type | Description |
|---|---|
Scatter
|
The assembled scatter trace. |
Source code in src/shaply/plots/usual/beeswarm.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
waterfall ¶
Waterfall plot for a single prediction (shap.plots.waterfall equivalent).
waterfall ¶
waterfall(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
sample_index: int = 0,
config: WaterfallConfig | None = None,
) -> Figure
Render a waterfall plot explaining a single prediction.
The plot starts at the model's expected value E[f(x)] and adds each
feature's contribution to reach the prediction f(x).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
base_values
|
object
|
Forwarded to :func: |
None
|
data
|
object
|
Forwarded to :func: |
None
|
feature_names
|
object
|
Forwarded to :func: |
None
|
output_index
|
object
|
Forwarded to :func: |
None
|
sample_index
|
int
|
Index of the instance to explain when the input holds several samples. |
0
|
config
|
WaterfallConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The waterfall figure. |
Source code in src/shaply/plots/usual/waterfall.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
scatter ¶
Dependence / scatter plot (shap.plots.scatter equivalent).
scatter ¶
scatter(
values: ExplanationLike | ArrayLike | object,
feature: str | int,
*,
color_feature: str | int | None = None,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: ScatterConfig | None = None,
) -> Figure
Render a SHAP dependence plot for a single feature.
The x-axis is the feature's value, the y-axis its SHAP value. Points may be colored by a second (interaction) feature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
feature
|
str | int
|
Name or index of the feature to place on the axes. |
required |
color_feature
|
str | int | None
|
Optional name or index of an interaction feature used for coloring. |
None
|
base_values
|
object
|
Forwarded to :func: |
None
|
data
|
object
|
Forwarded to :func: |
None
|
feature_names
|
object
|
Forwarded to :func: |
None
|
output_index
|
object
|
Forwarded to :func: |
None
|
config
|
ScatterConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The dependence figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If feature values ( |
Source code in src/shaply/plots/usual/scatter.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
heatmap ¶
Heatmap plot of SHAP values across instances (shap.plots.heatmap).
heatmap ¶
heatmap(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: HeatmapConfig | None = None,
) -> Figure
Render a heatmap of SHAP values with instances on the x-axis.
Rows are features (ordered by importance), columns are instances (ordered by their total SHAP output so similar explanations sit together).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
base_values
|
object
|
Forwarded to :func: |
None
|
data
|
object
|
Forwarded to :func: |
None
|
feature_names
|
object
|
Forwarded to :func: |
None
|
output_index
|
object
|
Forwarded to :func: |
None
|
config
|
HeatmapConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The heatmap figure. |
Source code in src/shaply/plots/usual/heatmap.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
decision ¶
Decision plot (shap.decision_plot equivalent).
Each instance is drawn as a line that starts at the model's expected value at
the bottom axis and accumulates SHAP values feature by feature going upward, so
its horizontal position at the top is the prediction f(x). Lines are colored
by their predicted output.
decision ¶
decision(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: DecisionConfig | None = None,
) -> Figure
Render a decision plot as a Plotly figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
base_values
|
object
|
Forwarded to :func: |
None
|
data
|
object
|
Forwarded to :func: |
None
|
feature_names
|
object
|
Forwarded to :func: |
None
|
output_index
|
object
|
Forwarded to :func: |
None
|
config
|
DecisionConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The decision figure. |
Source code in src/shaply/plots/usual/decision.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
force ¶
Force plot for a single prediction (shap.plots.force equivalent).
Positive contributions (red) push the prediction up and negative ones (blue)
push it down; the two blocks meet at f(x). The strip therefore spans
[base + sum(negatives), base + sum(positives)] with the red/blue boundary at
the prediction, exactly as in shap.
force ¶
force(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
sample_index: int = 0,
config: ForceConfig | None = None,
) -> Figure
Render an additive force plot explaining a single prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
base_values
|
object
|
Forwarded to :func: |
None
|
data
|
object
|
Forwarded to :func: |
None
|
feature_names
|
object
|
Forwarded to :func: |
None
|
output_index
|
object
|
Forwarded to :func: |
None
|
sample_index
|
int
|
Index of the instance to explain when the input holds several samples. |
0
|
config
|
ForceConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The force figure. |
Source code in src/shaply/plots/usual/force.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |