Raise drift alerts with an EWMA control chart
Why it matters EWMA charts watch model quality metrics in production because they react to small persistent shifts faster than raw thresholds.
An exponentially weighted moving average (EWMA) smooths a noisy metric such as a model's daily error rate, and control limits decide when the smoothed value has moved too far from normal.
Write ewma_alerts(x, lam, mu0, sigma, L). Start with z_0 = mu0. For t = 1..n (x[t - 1] is the t-th value): z_t = lam * x[t - 1] + (1 - lam) * z_(t-1), and the limit is L * sigma * sqrt(lam / (2 - lam) * (1 - (1 - lam) ** (2 t))). Alert at position t - 1 when |z_t - mu0| > limit_t. Return (numpy array of z_1..z_n, list of alert positions).
def ewma_alerts(x, lam, mu0, sigma, L)Example
ewma_alerts([0, 0, 3], 0.5, 0.0, 1.0, 3.0) gives (array([0., 0., 1.5]), []).
Understand the idea
Raw metrics like hourly error rate bounce around, so alerting on every spike is noisy. An EWMA keeps a running average that leans more on recent values: each new point gets weight lambda and the old average keeps 1 - lambda. A small persistent shift slowly pulls the average away from normal, and control limits tell you when that pull is too large to be chance.
Example: target 0, lambda 0.5, sigma 1, L 3. Values 0, 0, 3 give averages 0, 0, 1.5. The limit at step 3 is 3 * sqrt(0.5 / 1.5 * (1 - 0.5^6)) = 1.72, so 1.5 is still inside: no alert yet.
Rules: z_t = lam * x_t + (1 - lam) * z_(t-1); limit_t = L * sigma * sqrt(lam / (2 - lam) * (1 - (1 - lam)^(2t))).
ML monitoring tools use EWMA charts for accuracy, latency and drift scores.