Statistical
Kullback-Leibler (KL) Divergence & Population Stability Index (PSI) drift formulas
Measure probability distribution shift D_KL(P || Q) = SUM(P * LN(P / Q)) and symmetric credit-model Population Stability Index (PSI) in spreadsheets.
Monitor ML feature drift and credit-score shift with KL Divergence & PSI!
Compare two probability distributions over identical, mutually exclusive and exhaustive buckets. P is the observed live distribution and Q the baseline; neither is assumed to be an exact population truth. KL(P||Q)=sum(p*ln(p/q)) is asymmetric and expressed in nats. Individual terms can be negative while the full valid-distribution divergence is nonnegative.
PSI in this worksheet is the sum of forward and reverse KL, also called Jeffreys divergence. Thresholds such as 0.10 or 0.25 are heuristics, not universal regulatory standards or automatic instructions to retrain. Bucket definitions, sample size, seasonality and changes in collection can affect results. This page calculates KL and PSI, not Jensen-Shannon distance.
| Score Bucket | Training Baseline Q (B) | Live Traffic P (A) | KL Term P*LN(P/Q) & PSI Term |
|---|---|---|---|
| Prime | 0.25 | 0.50 | KL = +0.3466 | PSI = +0.1733 |
| Near-Prime | 0.25 | 0.30 | KL = +0.0547 | PSI = +0.0091 |
| Subprime | 0.50 | 0.20 | KL = -0.1833 | PSI = +0.2749 |
| Totals | 1.00 | 1.00 | D_KL(P||Q) = 0.2180 | PSI = 0.4573 (Drift!) |
Forward KL Divergence D_KL(P || Q) in nats
C2:C4 computes =A2 * LN(A2 / B2) for each bucket; SUM(C2:C4) gives D_KL(P || Q).
=IF(OR(COUNT(A2:B4)<>6,MIN(A2:B4)<0,ABS(SUM(A2:A4)-1)>1E-9,ABS(SUM(B2:B4)-1)>1E-9),"Invalid inputs",IF(COUNTIF(C2:C4,"Infinite divergence")>0,"Infinite divergence",ROUND(SUM(C2:C4), 4)))Symmetric Population Stability Index PSI = SUM((P - Q) * LN(P / Q))
Both columns must be nonnegative numeric probabilities summing to one within 1e-9. A bin with P=Q=0 contributes zero. P>0,Q=0 gives infinite forward KL; any one-sided zero gives infinite PSI. No smoothing is applied: adding pseudocounts would define different distributions.
=IF(OR(COUNT(A2:B4)<>6,MIN(A2:B4)<0,ABS(SUM(A2:A4)-1)>1E-9,ABS(SUM(B2:B4)-1)>1E-9),"Invalid inputs",IF(COUNTIF(D2:D4,"Infinite divergence")>0,"Infinite divergence",ROUND(SUM(D2:D4), 4)))Try the example
Use the original values or change them to test your understanding.