Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-274

PSI Computation

Problem

Return the population stability index between two aligned lists of bin proportions: sum((actual - expected) * ln(actual / expected)). Proportions at or below 1e-6 are smoothed to 1e-6, and bins where both are non-positive are skipped. Return 0.0 when the inputs are empty or their lengths differ.

Test cases

case 1
in: [[0.5,0.5],[0.6,0.4]]
expected: 0.04054651081081642
case 2
in: [[0.25,0.25,0.5],[0.2,0.3,0.5]]
expected: 0.02027325540540821
case 3
in: [[],[]]
expected: 0
case 4
in: [[0.5],[0.5]]
expected: 0
Starter codePython
import math
def psi(expected, actual):
    # Your code here
    pass

4 test cases · run your code against them in the editor