xAI: Statistical Tests & Divergences
The stride.xai.stats subpackage provides statistical two-sample hypothesis tests, summary moment displacement detectors, and distribution divergence metrics.
Overview
Statistical testing characterizes univariate and multivariate covariate shifts \(P(X)\) between sliding windows without requiring classifier predictions or ground-truth class labels.
from stride.xai.stats import (
StatisticalTestsDriftDetector,
StatisticalTestType,
DescriptiveStatisticsDriftDetector,
StatisticsType,
)
Key Components
| Class / Enum | Description |
|---|---|
StatisticalTestsDriftDetector |
Evaluates two-sample hypothesis tests across continuous features between reference and detection windows. |
StatisticalTestType |
Enumeration of supported statistical tests (KolmogorovSmirnov, AndersonDarling, Wasserstein). |
DescriptiveStatisticsDriftDetector |
Detects class-conditional relative shifts of summary statistics (mean, std, min, max, median) and of the class imbalance ratio. |
StatisticsType |
Enumeration of summary statistics evaluated (Mean, StandardDeviation, Min, Max, Median, ImbalanceRatio, All). |
Visualization
All plots return a matplotlib.figure.Figure and never call plt.show().
| Function | Description |
|---|---|
plot_boxplot, plot_violin, plot_histogram, plot_kde, plot_ecdf, plot_qq |
Distribution of selected features before and after the change, one row per feature and one column per class. |
plot_statistic_shift_heatmap |
Class × feature heatmap of the relative change of one descriptive statistic, from DescriptiveStatisticsDriftDetector.stat_shifts. |
plot_test_heatmap |
Class × feature heatmap of one test result (statistic, p-value or divergence) with the drifting pairs marked, from StatisticalTestsDriftDetector.drift_details[test]. |
from stride.xai.stats import plot_statistic_shift_heatmap, plot_test_heatmap
fig = plot_statistic_shift_heatmap(desc_detector.stat_shifts, statistic="mean")
fig = plot_test_heatmap(test_detector.drift_details["kolmogorov_smirnov"], value="stat")