Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Online ml River Drift State Inspection

From Leeroopedia


Knowledge Sources Domains Last Updated
River River Docs Online Machine Learning, Concept Drift, Model Monitoring 2026-02-08 16:00 GMT

Overview

Drift state inspection is a pattern for examining drift detector internal state to identify when and where concept drift occurred during model evaluation.

Description

When using drift-adaptive models in River, drift detection happens internally and is often invisible to the user. The drift state inspection pattern provides techniques for making these drift events observable, enabling users to understand the non-stationary dynamics of their data streams and the behavior of their adaptive models.

This pattern covers three primary inspection approaches:

1. DriftRetrainingClassifier state inspection: After each learn_one call, the wrapper's drift detector exposes its state via the drift_detected property. By checking model.drift_detector.drift_detected within the training loop, users can log the exact time steps where drift was detected and the model was reset or swapped.

2. ARFClassifier per-tree inspection: The Adaptive Random Forest tracks warnings and drifts at the individual tree level. The methods n_warnings_detected(tree_id) and n_drifts_detected(tree_id) provide aggregate or per-tree counts of detected events, revealing which trees were most affected by distributional changes.

3. Evaluation loop logging: By instrumenting the iter_progressive_val_score or a manual training loop with drift checks, users can build a timeline of drift events alongside performance metrics, enabling visual analysis of how model accuracy degrades at drift points and recovers after adaptation.

Usage

Use drift state inspection when:

  • You need to understand how many drift events occurred during an evaluation run.
  • You want to visualize the relationship between drift points and model performance changes.
  • You are debugging a drift-adaptive model to verify it is detecting and adapting correctly.
  • You want to compare how different drift detectors respond to the same data stream.
  • You need per-tree drift statistics for an ARF ensemble to understand which trees were most affected.

Theoretical Basis

Drift state inspection is rooted in the principle of observability in adaptive systems. While drift-adaptive models handle concept drift automatically, understanding their internal decisions is crucial for:

Validation: Confirming that drift was actually detected at known drift points in synthetic or semi-synthetic datasets.

Diagnosis: Identifying whether poor performance is caused by missed drifts (false negatives), premature resets (false positives), or slow adaptation.

Tuning: Adjusting drift detector parameters (e.g., ADWIN's δ, Page-Hinkley's threshold) based on observed detection behavior.

The inspection pattern leverages the fact that River's drift detectors maintain their state as accessible properties:

Inspection Points in the Training Loop:

For DriftRetrainingClassifier:
    model.drift_detector.drift_detected  -> bool (per step)
    model.drift_detector._drift_detected -> bool (internal state)

For ARFClassifier:
    model.n_warnings_detected()          -> int (total across all trees)
    model.n_warnings_detected(tree_id)   -> int (for specific tree)
    model.n_drifts_detected()            -> int (total across all trees)
    model.n_drifts_detected(tree_id)     -> int (for specific tree)

For standalone drift detectors:
    detector.drift_detected              -> bool (after each update)
    ADWIN-specific:
        detector.width                   -> int (current window size)
        detector.estimation              -> float (current mean estimate)
        detector.n_detections            -> int (total detections)

Pattern structure:

1. Initialize model and metric
2. For each (x, y) in dataset:
   a. Make prediction (test-then-train)
   b. Update metric
   c. Train model: model.learn_one(x, y)
   d. Check drift state and log if detected
3. After evaluation:
   a. Report total drifts detected
   b. Analyze drift timeline vs. performance curve

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment