shap.Explanation

class shap.Explanation(values: npt.NDArray[Any] | list[Any] | Explanation, base_values: npt.NDArray[Any] | list[Any] | float | None = None, data: npt.NDArray[Any] | pd.DataFrame | list[Any] | None = None, display_data: npt.NDArray[Any] | pd.DataFrame | None = None, instance_names: Sequence[str] | npt.NDArray[Any] | None = None, feature_names: Sequence[str] | npt.NDArray[Any] | Alias | None = None, output_names: Sequence[str] | npt.NDArray[Any] | str | Alias | None = None, output_indexes: npt.NDArray[Any] | None = None, lower_bounds: npt.NDArray[Any] | None = None, upper_bounds: npt.NDArray[Any] | None = None, error_std: npt.NDArray[Any] | None = None, main_effects: npt.NDArray[Any] | None = None, hierarchical_values: npt.NDArray[Any] | list[Any] | None = None, clustering: npt.NDArray[Any] | list[Any] | None = None, compute_time: float | None = None)

A sliceable set of parallel arrays representing a SHAP explanation.

Notes

The instance methods such as .max() return new Explanation objects with the operation applied.

The class methods such as Explanation.max return OpChain objects that represent a set of dot chained operations without actually running them.

__init__(values: npt.NDArray[Any] | list[Any] | Explanation, base_values: npt.NDArray[Any] | list[Any] | float | None = None, data: npt.NDArray[Any] | pd.DataFrame | list[Any] | None = None, display_data: npt.NDArray[Any] | pd.DataFrame | None = None, instance_names: Sequence[str] | npt.NDArray[Any] | None = None, feature_names: Sequence[str] | npt.NDArray[Any] | Alias | None = None, output_names: Sequence[str] | npt.NDArray[Any] | str | Alias | None = None, output_indexes: npt.NDArray[Any] | None = None, lower_bounds: npt.NDArray[Any] | None = None, upper_bounds: npt.NDArray[Any] | None = None, error_std: npt.NDArray[Any] | None = None, main_effects: npt.NDArray[Any] | None = None, hierarchical_values: npt.NDArray[Any] | list[Any] | None = None, clustering: npt.NDArray[Any] | list[Any] | None = None, compute_time: float | None = None) None

Methods

__init__(values[, base_values, data, ...])

cohorts(cohorts)

Split this explanation into several cohorts.

hstack(other)

Stack two explanations column-wise.

percentile(q[, axis])

Attributes

abs

argsort

base_values

Pass-through from the underlying slicer object.

clustering

Pass-through from the underlying slicer object.

data

Pass-through from the underlying slicer object.

display_data

Pass-through from the underlying slicer object.

error_std

Pass-through from the underlying slicer object.

feature_names

Pass-through from the underlying slicer object.

flip

hclust

hierarchical_values

Pass-through from the underlying slicer object.

identity

instance_names

Pass-through from the underlying slicer object.

lower_bounds

Pass-through from the underlying slicer object.

main_effects

Pass-through from the underlying slicer object.

max

mean

min

output_indexes

Pass-through from the underlying slicer object.

output_names

Pass-through from the underlying slicer object.

sample

shape

Compute the shape over potentially complex data nesting.

sum

upper_bounds

Pass-through from the underlying slicer object.

values

Pass-through from the underlying slicer object.

property base_values

Pass-through from the underlying slicer object.

property clustering

Pass-through from the underlying slicer object.

cohorts(cohorts: int | list[int] | tuple[int] | ndarray) Cohorts

Split this explanation into several cohorts.

Parameters:
cohortsint or array

If this is an integer then we auto build that many cohorts using a decision tree. If this is an array then we treat that as an array of cohort names/ids for each instance.

Returns:
Cohorts object
property data

Pass-through from the underlying slicer object.

property display_data

Pass-through from the underlying slicer object.

property error_std

Pass-through from the underlying slicer object.

property feature_names

Pass-through from the underlying slicer object.

property hierarchical_values

Pass-through from the underlying slicer object.

hstack(other: Explanation) Explanation

Stack two explanations column-wise.

Parameters:
othershap.Explanation

The other Explanation object to stack with.

Returns:
expshap.Explanation

A new Explanation object representing the stacked explanations.

property instance_names

Pass-through from the underlying slicer object.

property lower_bounds

Pass-through from the underlying slicer object.

property main_effects

Pass-through from the underlying slicer object.

property output_indexes

Pass-through from the underlying slicer object.

property output_names

Pass-through from the underlying slicer object.

property shape: tuple[int, ...]

Compute the shape over potentially complex data nesting.

property upper_bounds

Pass-through from the underlying slicer object.

property values

Pass-through from the underlying slicer object.