Practice in Lab: Measure binned drift with smoothing and fixed boundaries →
Measure binned drift with smoothing and fixed boundaries
Population stability index compares the proportions in fixed reference bins with those observed later. Zero occupancy makes logarithms undefined, so a declared smoothing convention is part of the calculation. Fit bin boundaries on reference data before observing the monitoring window.
Drift is not the same as model performance degradation. A feature distribution may shift harmlessly, while labels or conditional relationships shift without a large PSI. Report sample sizes, bin definitions and relevant slices. This exercise receives bin counts directly so it tests the monitoring arithmetic without pretending to detect every kind of dataset change.
import math
reference=[.5,.5];current=[.25,.75]
print(sum((b-a)*math.log(b/a) for a,b in zip(reference,current)))Review the design
Smoothing reduces instability but changes the estimate, especially on tiny windows. PSI thresholds are not universal laws; calibrate alerts against reference variation and observed model outcomes.
Your task
Implement psi(reference,current,epsilon=1e-6) for equal nonempty nonnegative finite bin counts with positive totals. Add epsilon to every bin count before normalizing each histogram; return sum((q-p)*log(q/p)). Require finite epsilon>0.
The explanation opens here once every check passes.