06-ab-testing-rollback compares two MODELS against a fixed traffic source. But the world a deployed model sees keeps changing on its own, independent of any model change at all: customer demographics shift, a new product launch changes typical purchase amounts, a sensor gets recalibrated. Data drift is exactly this, the INPUT distribution a model sees in production drifting away from the distribution it was trained on, and it needs its own real, quantifiable detection metric, separate from anything about model accuracy.
Implement bin_distribution (turning raw samples into a normalized histogram) and population_stability_index (PSI), the standard industry metric for quantifying distribution shift, plus detect_data_drift.
bin_distribution(samples, bin_edges) returns a normalized histogram summing to 1.0, with any empty bin's zero count replaced by a tiny floor value (1e-6) before normalizing.population_stability_index(expected, actual) returns sum((actual - expected) * ln(actual / expected)) over two ALREADY-NORMALIZED distributions.detect_data_drift(psi_value, threshold=0.2) is a plain threshold comparison.0 for two samples drawn from the SAME true distribution, regardless of sample size, and large for a genuinely shifted distribution.Open one at a time. Each gives away a little more than the last.
PSI's formula has the exact same SHAPE as a KL-divergence-style comparison (math-kl-divergence), a weighted sum of log-ratios between two distributions, but PSI specifically uses (actual - expected) as the weight instead of just actual or expected alone, which is what makes it symmetric in a way plain KL divergence isn't.
The floor value in bin_distribution matters more than it looks: without it, any bin that happens to get zero samples in EITHER distribution makes ln(actual/expected) blow up to +/-infinity, silently corrupting the whole PSI computation.
No results yet
Run your code to check it against the examples, or submit to run every test.