Observability, Covariate Drift & Population Stability Index (PSI)
CSC3119 · Lab

Population Stability Index (PSI) & Covariate Drift Detector

The hospital opens a geriatric wing. Shift the production age distribution and compute the real Population Stability Index, bin by bin — then decide whether to retrain.

  1. 1 · Predict0/1
  2. 2 · Experiment0/2
  3. 3 · Explain0/1
  4. 4 · Code it0/1
  5. 5 · Challenge
  6. 0/4 tasks done

Predict first

Commit to a guess before you touch anything. Being wrong here is how it sticks.

One bin: expected E = 0.10, actual A = 0.24. What is its PSI contribution (4 dp)?

Experiment

Move the controls and watch the outputs. Goals tick off automatically when you reach them.

PSI on patient age (10 reference deciles)

Training ages ~ Normal(52, 15). Each decile holds 10% of training patients.

PSI
0.000 · Stable
PSI = Σ (A − E) · ln(A / E), E = 0.10 per bin
DecileEA(A−E)·ln(A/E)
10.1000.1000.0000
20.1000.1000.0000
30.1000.1000.0000
40.1000.1000.0000
50.1000.1000.0000
60.1000.1000.0000
70.1000.1000.0000
80.1000.1000.0000
90.1000.1000.0000
100.1000.1000.0000

Explain it

Put what you saw into words. This is what the exam will ask you to do.

How does PSI measure covariate drift, what thresholds do we use, and how is this different from concept drift?

Code it

Write real code against real data. Python and SQL run right here in your browser and hidden tests check your work; the AI reviews it like an examiner.

Pythonexam

Population Stability Index

Write psi(expected, actual, bins=10):

  1. Bin edges are the quantiles of expected (deciles for bins=10), with the outer edges widened to ±infinity so every production value lands in a bin.
  2. E and A are the shares of expected and actual in each bin. Floor both at 1e-4 to avoid ln(0).
  3. Return Σ (A − E) · ln(A / E).

Then classify drift for the scenarios below with drift_level(value) → "stable" (< 0.1), "monitor" (0.1–0.25) or "retrain" (≥ 0.25).

Data in the working directory: stroke_sample.csv
Ctrl/⌘ + Enter to run

Challenge

Fixed variations, a new problem every day, and unlimited AI challenges built from your current settings.

Population Stability Index (PSI) Bin Contribution

In baseline training data, age bin [60–70] contained 20% of patients (E = 0.20). In recent production traffic, this bin jumped to 32% (A = 0.32). What is the PSI contribution of this single bin: (A − E) × ln(A / E)? (3 decimals)