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 [0.10,0.20,0.30,0.40,0.50,0.75] and 6 live scores are [0.55,0.65,0.70,0.80,0.85,0.95]: what are the empirical CDFs (cumulative distribution functions), the KS statistic D, and the comparison against the large-sample α=0.05 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 D=sup⁡t∣Fn(t)−Gm(t)∣ measures the largest vertical gap between the empirical CDFs (cumulative distribution functions) of a reference sample of size n and a live sample of size m. Because the critical threshold shrinks as (n+m)/(nm), millions of production predictions make tiny, harmless shifts statistically significant, so teams alert on effect size (D or PSI, population stability index) rather than p-values.

Steps

  1. Define the empirical CDFs: for reference scores x1,…,xn and live scores y1,…,ym, Fn(t)=1n∑i=1n1[xi≤t] and Gm(t)=1m∑j=1m1[yj≤t], where 1[⋅] is the indicator function. With n=m=6, each observation adds 1/6 to its CDF.
  2. Tabulate F6(t) and G6(t) across the sorted scores: up to t=0.50, five reference scores lie at or below t while zero live scores do (F6(0.50)=5/6, G6(0.50)=0). From t=0.55 to 0.70, F6(t)=5/6 while G6(t) steps from 1/6 to 3/6. At t=0.75, F6(0.75)=1 and G6(0.75)=3/6; thereafter G6(t) catches up to 1 at 0.95.
  3. Compute the KS statistic D=max⁡t∣F6(t)−G6(t)∣: the maximum vertical gap occurs on t∈[0.50,0.55), where D=∣5/6−0∣=5/6≈0.833.
  4. Compare against the critical value at significance level α=0.05: the large-sample asymptotic threshold is c(α)n+mnm with c(0.05)≈1.36. For n=m=6, this gives 1.361236=1.36/3≈0.785. Since 0.833>0.785, we reject the null hypothesis of equal distributions (small samples strictly require exact tables; here the exact two-sided permutation p-value is 24/924≈0.026<0.05).
  5. Explain why p-values misfire at scale: with n=m=1,000,000 live scores, the α=0.05 cutoff shrinks to 1.362/106≈0.0019. Even a small gap such as D=0.01 (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.
  6. Describe practical alerting rules: instead of alerting on p<0.05, production teams alert on effect-size thresholds (such as D>0.05 or D>0.10, or PSI thresholds) or evaluate KS on fixed-size windows, paying extra attention to score shifts near the decision threshold.

Common mistakes

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 Etest[ℓ]=Etrain[w(x) ℓ] and estimate w(x) using a domain classifier? Given ntrain=800 training points and ntest=200 unlabelled test points, four training examples receive calibrated domain probabilities P(test∣x)=[0.2,0.2,0.5,0.8] and per-example losses [0.1,0.2,0.3,0.8]: 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 n1=100, n2=300 and n3=600 examples return scalar weights 0.8, 0.5 and 0.2: what is the aggregated weight, and how do secure aggregation, differential privacy and non-IID (non-independent and identically distributed) data affect the protocol?