Population Stability Index

~20 mincode completion

Implement compute_psi(expected_proportions, actual_proportions) returning a single float.

Examples

Identical distributions: PSI is 0.0

Input
compute_psi([0.5, 0.5], [0.5, 0.5])
Output
0

Small shift: PSI should be positive and less than 0.1

Input
compute_psi([0.4, 0.4, 0.2], [0.35, 0.4, 0.25])
Output
0.01783

Swapped proportions: PSI is symmetric so same value both ways

Input
compute_psi([0.3, 0.7], [0.7, 0.3])
Output
0.67784

Hints

Hint 1

picks between two values elementwise without branching.

Hint 2

Double check the order of actual and expected in formula.

Requirements

  • expected_proportions: Bin proportions from reference data, shape (k,), sums to 1

  • actual_proportions: Bin proportions from current data, shape (k,), sums to 1

  • Return PSI as a single float.

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~20 min

8 employers weight this skill

3 big tech firms, 2 enterprise vendors, 1 defense company, 1 AI product company, 1 health and bio company. Top match scores 85.

Python
import numpy as np

def compute_psi(expected_proportions: np.ndarray, actual_proportions: np.ndarray) -> float:
    """
    Compute the Population Stability Index between two sets of bin proportions.

    Args:
        expected_proportions: Bin proportions from reference data, shape (k,), sums to 1
        actual_proportions:   Bin proportions from current data, shape (k,), sums to 1

    Returns:
        PSI as a single float.
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.