#148DDM Concept Drift DetectorMediumStatisticsML System DesignAsked atMeta · Google · Amazon
DDM Concept Drift Detector
Background
DDM (Drift Detection Method, Gama et al. 2004) detects concept drift on a streaming classifier by tracking the running error rate and its standard error . As new data arrives, if grows past historical minimums by enough, the detector raises warning or drift alerts. The canonical streaming-drift baseline.
Problem statement
Implement DDM(min_samples=30) as a class with update(is_error: int) -> "none" | "warn" | "drift":
- Track running (cumulative error rate) and .
- Track minimums seen so far.
- Below
min_samples: always return"none". p + s < p_{\min} + s_{\min}: update the minimums.p + s \ge p_{\min} + 3 s_{\min}: return"drift".p + s \ge p_{\min} + 2 s_{\min}: return"warn".- Else: return
"none".
Input
min_samples—int, minimum samples before any verdict (default30).update(is_error)—is_erroris0(correct) or1(incorrect).
Output
update returns one of "none", "warn", "drift".
Examples
Example 1 — stable stream
Stream: 200 zeros
Verdicts: mostly "none" (no drift)
Example 2 — sudden drift triggers detection
Stream: 50 zeros, then 50 ones
Final verdict: "warn" or "drift"
Example 3 — below min_samples
Stream of length 5 with min_samples=100
Verdicts: all "none"
Constraints
min_samples >= 2(need at least 2 samples to compute ).- State updates monotonically; the minimums never go up (they latch onto the lowest seen).
- Returns a
strfrom a fixed alphabet{"none", "warn", "drift"}.
Notes
- Why 2σ / 3σ. Same Gaussian thresholds as control charts. Roughly: = unusual; = action.
- Slow recovery. DDM never lowers after a drift event without a reset; production setups expose a
reset()after retraining.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •reference: stable stream of zeros stays none
- •example: below min_samples always returns none
- •sample: sudden error spike ends in drift