Advanced plots¶
Diagnostics and analyses that go beyond the standard shap figures.
beeswarm_ranges ¶
Combined beeswarm + feature-value-ranges figure.
The left panel is the usual SHAP beeswarm (impact on the model output); the right
panel shows, on a shared feature axis, the real distribution of each feature's
values as a horizontal density silhouette with an inner box. The silhouette is
colored with the same low-to-high scale as the beeswarm dots, so a glance at the
color already says which end is "low" and which is "high". Because raw features
live on very different scales, each silhouette is min-max normalized for geometry
while the true min/max are annotated at its ends - so an engineer reads
the impact, the operating range, and the value scale on the same line.
beeswarm_ranges ¶
beeswarm_ranges(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: BeeswarmRangesConfig | None = None,
) -> Figure
Render a beeswarm alongside each feature's real value distribution.
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
|
BeeswarmRangesConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The two-panel figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If feature values ( |
Source code in src/shaply/plots/advanced/beeswarm_ranges.py
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 80 81 82 83 84 85 86 87 | |
error_analysis ¶
Error-analysis plot: which features drive the model's mistakes.
Splits the instances into a correct and an error cohort and compares the mean SHAP value of each feature between them, ordered by the size of the gap. Features with a large gap are the ones the model relies on differently when it is wrong - usually the most profitable place to look in an industrial setting.
error_analysis ¶
error_analysis(
values: ExplanationLike | ArrayLike | object,
*,
errors: ArrayLike | None = None,
y_true: ArrayLike | None = None,
y_pred: ArrayLike | None = None,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: ErrorAnalysisConfig | None = None,
) -> Figure
Compare mean SHAP values between correct and mis-predicted instances.
Provide the error cohort either directly via errors (a boolean mask, True
for mistakes) or via y_true and y_pred (mismatch defines an error).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
errors
|
ArrayLike | None
|
Boolean mask, |
None
|
y_true
|
ArrayLike | None
|
Ground-truth and predicted labels; an error is |
None
|
y_pred
|
ArrayLike | None
|
Ground-truth and predicted labels; an error is |
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
|
ErrorAnalysisConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The error-analysis figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the error cohort is under-specified, mis-sized, or empty/complete. |
Source code in src/shaply/plots/advanced/error_analysis.py
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 74 75 76 77 78 79 80 | |
explanation_archetypes ¶
Explanation archetypes: typical SHAP-profile patterns across instances.
Clusters instances by their SHAP profile and shows each cluster's mean SHAP per feature as a heatmap row. The archetypes read as the model's recurring "reasons" - e.g. distinct failure modes or operating regimes - rather than one instance at a time.
explanation_archetypes ¶
explanation_archetypes(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: ExplanationArchetypesConfig | None = None,
) -> Figure
Cluster instances by SHAP profile and show each archetype's mean 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
|
ExplanationArchetypesConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The archetypes heatmap. |
Source code in src/shaply/plots/advanced/explanation_archetypes.py
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 | |
feature_clustering ¶
Feature-clustering / redundancy heatmap based on SHAP similarity.
Two features are redundant for the model when their per-sample SHAP vectors are strongly correlated: they push predictions in lockstep. This plot shows the SHAP-correlation matrix reordered by average-linkage clustering, so blocks of mutually correlated (often droppable) features stand out.
feature_clustering ¶
feature_clustering(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: FeatureClusteringConfig | None = None,
) -> Figure
Render a clustered heatmap of SHAP correlation between features.
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
|
FeatureClusteringConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The clustered correlation heatmap. |
Source code in src/shaply/plots/advanced/feature_clustering.py
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 | |
importance_by_cohort ¶
Cohort-wise feature importance.
Compares mean(|SHAP|) per feature across cohorts of instances, revealing that
a feature can dominate in one operating regime and be negligible in another.
Cohorts are given explicitly, or built by quantile-binning one feature.
importance_by_cohort ¶
importance_by_cohort(
values: ExplanationLike | ArrayLike | object,
*,
cohorts: ArrayLike | None = None,
by_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: ImportanceByCohortConfig | None = None,
) -> Figure
Render feature importance split by cohort.
Provide the cohorts either directly via cohorts (one label per instance)
or via by_feature (quantile-bin that feature into config.n_cohorts).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
cohorts
|
ArrayLike | None
|
One cohort label per instance. |
None
|
by_feature
|
str | int | None
|
Name or index of a feature to quantile-bin into cohorts (needs |
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
|
ImportanceByCohortConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The grouped importance figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither or both cohort sources are given, or sizes mismatch. |
Source code in src/shaply/plots/advanced/importance_by_cohort.py
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 74 75 76 77 78 | |
importance_ci ¶
Global importance with bootstrap confidence intervals.
Like the bar plot, but each mean(|SHAP|) bar carries a bootstrap confidence
interval over instances, so a fragile ranking (wide, overlapping intervals) is
not mistaken for a robust one.
importance_ci ¶
importance_ci(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: ImportanceCIConfig | None = None,
) -> Figure
Render global feature importance with bootstrap confidence intervals.
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
|
ImportanceCIConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The importance figure with error bars. |
Source code in src/shaply/plots/advanced/importance_ci.py
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 | |
interaction_heatmap ¶
Pairwise SHAP-interaction heatmap.
Given a SHAP interaction tensor, this ranks features by total interaction strength and shows the matrix of mean absolute interaction between the top pairs. Bright off-diagonal cells flag features that act together on the prediction - the closest SHAP gets to surfacing coupled effects.
interaction_heatmap ¶
interaction_heatmap(
values: ArrayLike | object,
*,
feature_names: Sequence[str] | None = None,
config: InteractionHeatmapConfig | None = None,
) -> Figure
Render a heatmap of mean absolute SHAP interactions between features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ArrayLike | object
|
A |
required |
feature_names
|
Sequence[str] | None
|
Feature labels; inferred or generated when omitted. |
None
|
config
|
InteractionHeatmapConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The interaction heatmap. |
Source code in src/shaply/plots/advanced/interaction_heatmap.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 | |
monotonicity_check ¶
monotonicity_check(
values: ExplanationLike | ArrayLike | object,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: MonotonicityConfig | None = None,
) -> Figure
Rank features by the monotonicity of their value-to-SHAP relationship.
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
|
MonotonicityConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The monotonicity figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If feature values ( |
Source code in src/shaply/plots/advanced/monotonicity.py
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 | |
response_curve ¶
Response-curve plot: smoothed SHAP effect of a feature with tipping points.
For a single feature this shows the smoothed mean SHAP value as a function of the feature's value, a spread band, and the values where the mean effect crosses zero (the "tipping points" where the feature switches from lowering to raising the prediction). It is an actionable, PDP/ALE-flavored read of a dependence plot.
Note: SHAP effects are associational, not causal - read a tipping point as "the value above which this feature is associated with a higher model output", not as a proven physical cause.
response_curve ¶
response_curve(
values: ExplanationLike | ArrayLike | object,
feature: str | int,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: ResponseCurveConfig | None = None,
) -> Figure
Render the smoothed SHAP response curve of a single 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 profile. |
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
|
ResponseCurveConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The response-curve figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If feature values ( |
Source code in src/shaply/plots/advanced/response_curve.py
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 80 81 82 83 84 85 86 87 88 89 90 | |
scatter_ranges ¶
Dependence scatter framed by its two axes' marginal distributions.
The center panel is a standard SHAP dependence plot for one feature: x is the
feature's real value, y its SHAP value, and points are colored by the (also
redundant, but helpful to the eye) feature value on the same low-to-high scale
used across shaply. Around it, four marginal panels repeat each axis'
distribution in two complementary shapes:
- top: a box plot of the real values, gradient-colored left-to-right.
- bottom: a density silhouette of the real values, gradient-colored.
- left: a plain gray density silhouette of the SHAP values.
- right: a plain gray box plot of the SHAP values.
Only the x-axis (real value) marginals are colored, since that color already carries meaning (low/high); the y-axis (SHAP value) marginals stay neutral.
scatter_ranges ¶
scatter_ranges(
values: ExplanationLike | ArrayLike | object,
feature: str | int,
*,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: ScatterRangesConfig | None = None,
) -> Figure
Render a dependence scatter framed by its axes' marginal distributions.
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 |
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
|
ScatterRangesConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The framed scatter figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If feature values ( |
Source code in src/shaply/plots/advanced/scatter_ranges.py
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 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
shap_surface ¶
2D SHAP interaction surface over the plane of two features.
Bins the (feature_x, feature_y) plane and shows the mean SHAP value of one
feature in each cell. Bright/dark regions expose operating regions where the
feature helps or hurts the prediction, and how a second feature modulates it.
shap_surface ¶
shap_surface(
values: ExplanationLike | ArrayLike | object,
feature_x: str | int,
feature_y: str | int,
*,
shap_of: str | int | None = None,
base_values: object = None,
data: ArrayLike | None = None,
feature_names: Sequence[str] | None = None,
output_index: int | None = None,
config: ShapSurfaceConfig | None = None,
) -> Figure
Render the mean SHAP surface over the plane of two features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ExplanationLike | ArrayLike | object
|
SHAP values as an |
required |
feature_x
|
str | int
|
Features spanning the horizontal and vertical axes. |
required |
feature_y
|
str | int
|
Features spanning the horizontal and vertical axes. |
required |
shap_of
|
str | int | None
|
Which feature's SHAP value to average in each cell; defaults to
|
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
|
ShapSurfaceConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Figure
|
The surface figure. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If feature values ( |
Source code in src/shaply/plots/advanced/shap_surface.py
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 74 75 76 77 78 79 | |