Distribution Shift Detection

Distribution Shift Detection#

The shift module provides methods for detecting and quantifying distribution shifts between training and deployment data.

Base Class#

BaseShiftDetector()

Abstract base class for distribution shift detection methods.

Shift Detectors#

MMDShiftDetector([sigma])

Kernel Maximum Mean Discrepancy with Gaussian (RBF) kernel.

EnergyShiftDetector()

Energy distance – Szekely & Rizzo, 2013.

KSShiftDetector()

One-dimensional Kolmogorov–Smirnov test (per feature, max statistic).

ClassifierShiftDetector([clf_factory, device])

Train a logistic regression to separate reference and test.

BBSDDetector

alias of ClassifierShiftDetector

LabelShiftDetector(num_classes[, calibrated])

Black-Box Shift Detection for label shift.

ImportanceWeightingShift([method, alpha])

Importance weighting for covariate shift adaptation.

Metrics#

energy_distance(x, y)

Szekely–Rizzo energy distance, O(n²) naive implementation.

total_variation(p, q[, eps])

Total variation between discrete distributions p and q.

population_stability_index(p_hist, q_hist[, eps])

Classic tabular PSI used in credit scoring.

wasserstein_distance(x, y[, p, max_iter, ...])

Wasserstein distance (Earth Mover's Distance) between two empirical distributions.

sliced_wasserstein_distance(x, y[, ...])

Sliced Wasserstein distance between two empirical distributions.

Visualization#

plot_feature_histograms(ref, test[, ...])

Overlay 1-D histograms for a handful of features.

plot_embedding_space(ref_emb, test_emb[, ...])

Visualize reference and test embeddings in 2D space.

plot_confidence_distributions(...[, bins, show])

Compare model confidence distributions between reference and test data.

plot_shift_severity(severity_values, ...[, ...])

Plot shift scores against a severity measure (e.g., rotation degrees, time).

plot_ks_statistics(ks_stats[, ...])

Bar chart of per-feature KS statistics showing which features shifted most.