Sub topic 2
Censoring and selection bias in partially labeled data
This chapter assumes you know binary classification metrics (accuracy, precision, recall, ROC AUC), basic pandas and scikit-learn, and that your system logs every prediction it makes.
Censoring and selection bias
Censoring means some true outcomes are not yet known. Selection bias means the rows that have labels differ from all predictions. Labels often arrive only for cases that trigger a follow-up, such as customers who complain or loans that default early. Accuracy computed on labeled rows only describes that subset.
Label-free proxy signals and their limits
Proxies are measurable quantities that correlate with errors, such as the manual review rate, complaint volume, or the share of high-score predictions. They change before labels arrive, so they give early warnings. They cannot give accuracy directly, because a proxy can move for reasons unrelated to model errors.
Detecting data and prediction drift
Drift means an input or score distribution has moved away from a reference period. The population stability index (PSI) compares the two distributions bin by bin. A common rule of thumb treats PSI above 0.2 as a major shift, but treat that threshold as a starting point.
import numpy as np
def psi(expected, actual, bins=10):
"""Population stability index between a reference sample and a new sample."""
edges = np.quantile(expected, np.linspace(0, 1, bins + 1))
actual = np.clip(actual, edges[0], edges[-1])
e = np.histogram(expected, edges)[0] / len(expected)
a = np.histogram(actual, edges)[0] / len(actual)
e = np.clip(e, 1e-6, None)
a = np.clip(a, 1e-6, None)
return float(np.sum((a - e) * np.log(a / e)))Drift shows that the model sees new data. It does not show that accuracy fell.
Calibration: when predicted probabilities can be trusted
A model is calibrated when a score of 0.3 means about 30 percent of such cases are positive. Check calibration with a reliability table that compares each score bin's mean prediction with its observed positive rate. The numbers below are illustrative.
| Score bin | Mean predicted | Observed positive rate | Calibrated? |
|---|---|---|---|
| 0.0 to 0.2 | 0.12 | 0.10 | Yes |
| 0.2 to 0.5 | 0.34 | 0.41 | Roughly |
| 0.5 to 1.0 | 0.78 | 0.55 | No |
Exercise
A fraud model has AUC 0.91 on labeled transactions, but only transactions that a reviewer examined received labels. Why might the 0.91 overstate performance on all transactions?
Show answer
The reviewed transactions are selected, often because the model flagged them or because they looked suspicious. The labeled set is therefore not representative of all predictions, so the AUC measures performance on that selected subset only.