How do you use the two-sample KS (Kolmogorov–Smirnov) test to detect drift in a model's prediction scores? Suppose 6 reference scores are and 6 live scores are : what are the empirical CDFs (cumulative distribution functions), the KS statistic , and the comparison against the large-sample critical value, and why do production teams alert on effect size rather than p-values?
ML systems and evaluation, Monitoring
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can compute the two-sample KS (Kolmogorov–Smirnov) statistic by hand, apply its rejection rule, and avoid the large-sample p-value trap in production monitoring.
Key idea
The two-sample KS statistic measures the largest vertical gap between the empirical CDFs (cumulative distribution functions) of a reference sample of size and a live sample of size . Because the critical threshold shrinks as , millions of production predictions make tiny, harmless shifts statistically significant, so teams alert on effect size ( or PSI, population stability index) rather than p-values.
Steps
- Define the empirical CDFs: for reference scores and live scores , and , where is the indicator function. With , each observation adds to its CDF.
- Tabulate and across the sorted scores: up to , five reference scores lie at or below while zero live scores do (, ). From to , while steps from to . At , and ; thereafter catches up to at .
- Compute the KS statistic : the maximum vertical gap occurs on , where .
- Compare against the critical value at significance level : the large-sample asymptotic threshold is with . For , this gives . Since , we reject the null hypothesis of equal distributions (small samples strictly require exact tables; here the exact two-sided permutation p-value is ).
- Explain why p-values misfire at scale: with live scores, the cutoff shrinks to . Even a small gap such as (one percentage point of CDF), from diurnal traffic mix or numerical rounding, is then far beyond the cutoff and gives a tiny p-value and constant false alerts.
- Describe practical alerting rules: instead of alerting on , production teams alert on effect-size thresholds (such as or , or PSI thresholds) or evaluate KS on fixed-size windows, paying extra attention to score shifts near the decision threshold.
Common mistakes
- Treating the asymptotic formula as exact on tiny samples without noting that exact KS permutation tables should be used.
- Alerting on over millions of daily predictions, which floods on-call teams whenever minor, harmless shifts occur.
- Relying only on KS when tail behaviour matters; because tracks the maximum CDF gap, it is most sensitive near the median and weak at detecting thin-tail shifts.
How long your answer should be
3–4 minutes: empirical CDFs, D = 5/6 calculation, critical value check, and two sentences on effect-size alerting.
Read this
Previous in ML systems and evaluation: Under covariate shift, how do you derive the importance-weighted loss and estimate using a domain classifier? Given training points and unlabelled test points, four training examples receive calibrated domain probabilities and per-example losses : what are their importance weights, the weighted loss, and the ESS (effective sample size), and why does this fail under concept drift?
Next in ML systems and evaluation: How does FedAvg (federated averaging) train a shared model without centralising raw data, and what privacy risks remain? In one round, three clients with , and examples return scalar weights , and : what is the aggregated weight, and how do secure aggregation, differential privacy and non-IID (non-independent and identically distributed) data affect the protocol?