TorchedUp
ProblemsPremium
TorchedUp
PSI Drift ScoreMedium
ProblemsPremium

Population Stability Index

Implement the PSI metric for distribution drift on a single feature.

Signature: def psi(expected: list, actual: list, n_bins: int = 10) -> float

Steps:

  1. Compute n_bins quantile boundaries from expected
  2. Bucket both expected and actual using those boundaries
  3. For each bin, compute (a_pct - e_pct) * log(a_pct / e_pct) and sum

Clip percentages to 1e-6 to avoid log(0).

Rule of thumb: <0.1 no shift, 0.1-0.25 moderate, >0.25 significant.

Math

Asked at

Python (numpy)0/3 runs today

Test Results

○identical
○mild shift
○large shift🔒 Premium
Advertisement