Population Stability Index

easy
Unit 7 · Economics0/3 to milestone

The PSI is the credit-scoring industry's standard drift metric: bin a variable using the reference (training) distribution, then compare the share of the current population in each bin.

PSI=∑i(ai−ei)ln⁡aiei\text{PSI} = \sum_i (a_i - e_i)\ln\frac{a_i}{e_i}

where eie_i and aia_i are the expected (reference) and actual (current) proportions in bin i.

Implement:

  • quantile_edges(reference, bins=10): the interior bin edges at the reference's quantiles 1/bins, 2/bins, … (bins - 1 edges)
  • proportions(x, edges, eps=1e-4): the share of x in each bin (use np.searchsorted(edges, x, side='right') for bin indices), with each proportion floored at eps so the log is defined
  • psi(reference, current, bins=10)
  • psi_status(value): "stable" below 0.1, "moderate" below 0.25, otherwise "shifted"
#monitoring#drift-detection#credit-risk2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Population Stability Index · TechGradify