#148DDM Concept Drift DetectorMedium

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 pp and its standard error ss. As new data arrives, if p+sp + s 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 pp (cumulative error rate) and s=p(1p)/ns = \sqrt{p(1-p)/n}.
  • Track minimums pmin,sminp_{\min}, s_{\min} 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_samplesint, minimum samples before any verdict (default 30).
  • update(is_error)is_error is 0 (correct) or 1 (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 ss).
  • State updates monotonically; the minimums never go up (they latch onto the lowest p+sp + s seen).
  • Returns a str from a fixed alphabet {"none", "warn", "drift"}.

Notes

  • Why 2σ / 3σ. Same Gaussian thresholds as control charts. Roughly: >2σ> 2\sigma = unusual; >3σ> 3\sigma = action.
  • Slow recovery. DDM never lowers pminp_{\min} 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