Types¶
types
¶
Type definitions for shap-monitor.
Classes¶
Period
¶
Bases: NamedTuple
A time period defined by start and end dates.
Can be used as a tuple: Period(start, end) or with named fields:
Period(start=date(2025, 1, 1), end=date(2025, 1, 7))
Backend
¶
Bases: Protocol
Protocol for backend storage systems.
Any backend that implements the read, write, and delete methods can be used.
Functions¶
read
¶
read(
start_dt: datetime | date | None = None,
end_dt: datetime | date | None = None,
batch_id: str | None = None,
model_version: str | None = None,
) -> DFrameLike
Read data from the backend.
Source code in shapmonitor/types.py
39 40 41 42 43 44 45 46 47 | |
write
¶
write(batch: ExplanationBatch) -> None
Write data to the backend.
Source code in shapmonitor/types.py
49 50 51 | |
delete
¶
delete(cutoff_dt: datetime) -> None
Delete data before a certain datetime.
Source code in shapmonitor/types.py
53 54 55 | |
ExplanationLike
¶
Bases: Protocol
Protocol for SHAP explanation objects.
Any SHAP explanation object that implements the values and base_values attributes can be used.
ExplainerLike
¶
Bases: Protocol
Protocol for SHAP explainer objects.
Any SHAP explainer (TreeExplainer, KernelExplainer, etc.) that implements the shap_values method can be used.
Functions¶
explain_row
¶
explain_row(X: ArrayLike) -> ExplanationLike
Compute SHAP for a single input feature row.
Source code in shapmonitor/types.py
92 93 94 | |
ExplanationBatch
dataclass
¶
ExplanationBatch(
timestamp: datetime,
batch_id: str,
model_version: str,
n_samples: int,
base_values: ArrayLike,
shap_values: dict[str, ArrayLike],
feature_values: dict[str, ArrayLike] | None = None,
predictions: ArrayLike | None = None,
)
A batch of explanations to be stored.
This corresponds to one row in the Parquet backend. Feature-specific columns (shap_, feat_) are stored as dicts mapping feature names to arrays of values.
Functions¶
to_dataframe
¶
to_dataframe() -> DataFrame
Convert the ExplanationBatch to a pandas DataFrame.
Source code in shapmonitor/types.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |