TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
TorchedUp
LearnBetaProblemsSystem DesignSoonPremium
←

122. PSI Drift Score

Medium

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

PSI=i=1∑B​(ai​−ei​)log(ei​ai​​)

Asked at

NumPy

import numpy as np

 

def psi(...):

    pass

🔒

Premium problem

Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.

Upgrade to PremiumBack to problems

Already premium?