Concept Drift & Adaptation
Batch ML assumes the training and serving distributions match. On a live stream they routinely do not: user behaviour shifts, fraud patterns evolve, sensors age, a pandemic rewrites demand overnight. When the data-generating process changes over time, we call it concept drift, and a model that ignores it silently rots. This lesson covers detecting drift and adapting to it, the concerns at the heart of libraries like river.
The forecasting thread
This is the exact failure the site's running daily-demand model keeps hitting. The canonical series (from the project-loop hub) has a regime shift at day 400 — a permanent level jump. To a batch model it's invisible until the error blows up; a streaming system running a drift detector on the residuals catches it within days and adapts online. Concept drift is the demand problem's day-400 shift, generalized to "the world keeps changing."
What is drifting?
Write the joint distribution the stream is drawn from at time as . Drift is any change in over time, and it comes in distinct flavours that call for different responses:
- Virtual drift / covariate shift: changes but does not. The input distribution moves (new users, new regions) yet the decision boundary is still correct. Often you can tolerate this.
- Real / concept drift: changes. The relationship between features and label is different now; the old decision boundary is wrong. This is the dangerous one.
- Label / prior drift: changes (e.g. the base rate of fraud rises).
Drift also has a temporal shape:
- Sudden: an abrupt switch (a policy change, a sensor swap).
- Gradual: the new concept slowly displaces the old.
- Incremental: a continuous slow morph.
- Recurring: old concepts return (weekday vs weekend, seasonal).
Drift ≠ noise, and covariate shift ≠ concept drift
The hard part of detection is distinguishing a genuine change in the concept from ordinary sampling noise. And a spike in alone (covariate shift) may need no action, while a change in demands retraining. Monitoring input statistics is not enough. You have to watch the model's error on labelled feedback.
Detecting drift
Detectors watch a signal (usually the model's streaming error rate) and raise an alarm when it changes more than chance allows.
DDM: Drift Detection Method
DDM tracks the online error rate and its standard deviation . For a stationary concept a well-fit classifier's error should not grow, so DDM records the minimum seen so far and flags:
- a warning when (start buffering new data for a fresh model),
- drift when (replace the model).
The / bands come straight from a normal approximation to the error rate.
ADWIN: Adaptive Windowing
ADWIN keeps a window of recent values and asks: is there a split of into an older part and a newer part whose means differ by more than chance? It drops the old part exactly when
where is the harmonic mean of the two sub-window sizes and is a confidence parameter. When the test fires, ADWIN shrinks the window to just the recent segment, so the window length itself becomes an estimate of "how far back the current concept extends." A clever bucket scheme (exponential histograms, as in DGIM) keeps its memory logarithmic in the window size.
Concept drift: detect, then adapt
At the dashed line the concept changes. A static model (rose) never recovers — its error stays elevated. The adaptive model (teal) runs an ADWIN-style detector on its error stream; when two halves of its window diverge by more than the Hoeffding cut it flags drift (flag), drops the stale window, retrains, and error falls back to baseline. Raise the confidence δ to trip the detector sooner — at the cost of more false alarms on stationary data.
The confidence is the classic tuning knob: raise it and shrinks, so drift is caught sooner but false alarms on stationary data rise; lower it and the detector is conservative, adapting late but rarely crying wolf. This is the detection-delay vs false-alarm trade-off every drift detector must navigate.
Adapting to drift
Detection is half the job; the model then has to change. Strategies, roughly in order of sophistication:
- Retrain on a window. Keep the last examples (or the post-ADWIN window) and refit. Simple, and the window automatically forgets stale data.
- Incremental / online update. Use an online learner (previous lesson) that continuously tracks the current concept; a decaying step size or explicit forgetting factor down-weights the past.
- Detect-and-reset. Pair any learner with a detector (ADWIN/DDM); on an alarm, reset or spin up a fresh model on recent data. This is what the animation above shows.
- Ensembles. Maintain a pool of models trained on different periods and weight them by recent accuracy (e.g. Dynamic Weighted Majority, Adaptive Random Forest). Recurring concepts are handled gracefully because an old expert regains weight when its concept returns.
Hoeffding trees: decision trees for streams
A batch decision tree needs all the data to choose each split. The Hoeffding tree (Very Fast Decision Tree) instead decides how many examples are enough. The Hoeffding bound says that after independent observations of a quantity in range , the true mean is within
of the observed mean, with probability . So the tree accumulates split-quality statistics (e.g. information gain ) at a leaf and splits as soon as the best attribute beats the runner-up by more than : . That guarantees, with high probability, the same split the batch tree would have chosen — using only a small prefix of the stream and memory per example. The Hoeffding Adaptive Tree (HAT) adds an ADWIN detector at each node, growing an alternate subtree when drift is detected and swapping it in once it wins.
Python: adaptive learning with river
from river import tree, drift, metrics
model = tree.HoeffdingAdaptiveTreeClassifier() # HT + per-node ADWIN
detector = drift.ADWIN(delta=0.002)
metric = metrics.Accuracy()
for x, y in stream: # one pass over an evolving stream
y_pred = model.predict_one(x)
metric.update(y, y_pred)
model.learn_one(x, y) # incremental update
detector.update(int(y_pred != y)) # feed the error signal
if detector.drift_detected:
print(f"drift detected — accuracy now {metric.get():.3f}")
Exercise
A recommender sees a wave of new users from a new country: the input distribution P(X) shifts noticeably, but the mapping from features to preferences P(Y|X) is unchanged. What kind of drift is this, and what does it imply?
Need a hint?
Which distribution actually changed — P(X) or P(Y|X)? Is the decision boundary still correct?
Exercise
ADWIN cuts its window when |μ̂_W0 − μ̂_W1| > ε_cut, where ε_cut = √( (1/2m)·ln(4|W|/δ) ). You increase the confidence parameter δ. What is the effect?
Need a hint?
A larger δ makes ε_cut smaller. A smaller threshold is easier to exceed.
Key takeaways
- Concept drift is change in . Distinguish covariate shift () from dangerous real drift (); note whether it is sudden, gradual, incremental, or recurring.
- DDM flags drift when the error rate exceeds / bands; ADWIN drops the stale window when two sub-window means differ by more than a Hoeffding cut .
- The detector's confidence trades detection delay against false alarms.
- Adapt by windowed retraining, online updates, detect-and-reset, or ensembles. Hoeffding trees grow decision trees on streams using the Hoeffding bound to decide when a split is justified.
Related concepts
- Online Learning & Regret: the incremental learners that track a moving concept
- Streaming ML in Production: monitoring and alerting on drift in a live system
- Decision Trees: the batch trees Hoeffding trees stream-ify