Drift Detection & Descriptors
The stride.drift subpackage provides sequential drift monitoring algorithms, error stream tracking, and post-detection characterization descriptors.
Overview
Streaming drift detection in STRIDE wraps River sequential detectors to monitor binary classification error streams \(e_t \in \{0, 1\}\). When an alarm is triggered, the descriptor reconstructs the transition onset, duration, and error trajectory.
Key Components
| Class / Structure | Description |
|---|---|
BinaryErrorDriftDescriptor |
Wraps River drift detectors (e.g. DDM, EDDM, ADWIN) and applies CUSUM, threshold, or gradient lookback to estimate drift onset and duration. |
DualADWIN |
Dual-threshold ADWIN wrapper running coupled estimators for simultaneous early warning (\(\delta_{\text{warn}}\)) and confirmed drift (\(\delta_{\text{drift}}\)). |
DriftDescription |
Dataclass storing reconstructed drift event parameters (detected_at, drift_start_index, drift_end_index, duration, error_rate_at_start, error_rate_at_peak, severity). |
API Specification
stride.drift
Drift detection methods, sequential error descriptors, and drift event tracking.
BinaryErrorDriftDescriptor
BinaryErrorDriftDescriptor(
warning_grace_period=3,
rate_calculation_sample_size=100,
ddm=DDM(),
lookback_method="cusum",
lookforward_method="peak",
degradation_only=True,
)
Track and characterize concept drifts identified by sequential error detectors.
Wraps River detectors (such as DDM and EDDM) to continuously monitor the binary error stream of an online model (\(e_t \in \{0, 1\}\)). When a warning or drift signal is triggered, it applies change-point lookback algorithms (CUSUM, threshold, gradient) to estimate the actual onset timestamp and lookforward methods to locate the drift peak.
Attributes:
| Name | Type | Description |
|---|---|---|
warning_grace_period |
Allowed consecutive non-warning steps before warning chain resets. |
|
rate_calculation_sample_size |
Number of samples used to calculate local error rates. |
|
ddm |
Underlying River binary drift and warning detector instance. |
|
lookback_method |
Change-point algorithm used to locate onset ("cusum", "threshold", "gradient", "none"). |
|
lookforward_method |
Algorithm used to estimate stabilization ("peak", "recovery", "none"). |
|
error_history |
list[int | float]
|
Window of recent error signals. |
complete_error_history |
list[int | float]
|
Full recorded error stream sequence. |
drift_detected |
Flag indicating whether drift occurred at current timestep. |
|
last_detected_drift |
DriftDescription | None
|
Most recent |
current_index |
Current stream iteration index. |
|
degradation_only |
Whether to restrict detections to error degradation rather than improvement. |
Initialize the binary error drift descriptor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warning_grace_period
|
int
|
Allowed non-warning steps within a warning chain. |
3
|
rate_calculation_sample_size
|
int
|
Window size for moving error rate averages. |
100
|
ddm
|
Any
|
River drift detector instance with |
DDM()
|
lookback_method
|
str
|
Method for onset estimation ("cusum", "threshold", "gradient", "none"). |
'cusum'
|
lookforward_method
|
str
|
Method for end/peak estimation ("peak", "recovery", "none"). |
'peak'
|
degradation_only
|
bool
|
Whether to restrict detections to error degradation rather than improvement. |
True
|
Source code in src/stride/drift/binary_descriptor.py
describe_drift
Return the DriftDescription object for the most recent drift event.
Returns:
| Type | Description |
|---|---|
DriftDescription | None
|
Description object containing duration, onset, and error rates, or |
Source code in src/stride/drift/binary_descriptor.py
find_drift_end_peak
Estimate peak error rate timestamp following drift alarm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection_idx
|
int
|
Stream index where drift alarm was raised. |
required |
lookforward_window
|
int
|
Maximum subsequent samples evaluated. |
200
|
Returns:
| Type | Description |
|---|---|
int
|
Sample index corresponding to maximum error rate window. |
Source code in src/stride/drift/binary_descriptor.py
find_drift_end_recovery
Estimate stabilization point where error rates return toward baseline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection_idx
|
int
|
Stream index where drift alarm was raised. |
required |
lookforward_window
|
int
|
Maximum subsequent samples evaluated. |
200
|
Returns:
| Type | Description |
|---|---|
int
|
Sample index representing error recovery point. |
Source code in src/stride/drift/binary_descriptor.py
find_drift_start_cusum
Estimate drift onset using CUSUM change-point detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection_idx
|
int
|
Stream index where drift alarm was raised. |
required |
lookback_window
|
int
|
Maximum history window examined prior to detection. |
300
|
Returns:
| Type | Description |
|---|---|
int
|
Estimated sample index representing drift onset. |
Source code in src/stride/drift/binary_descriptor.py
find_drift_start_gradient
Estimate drift onset using error rate gradient acceleration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection_idx
|
int
|
Stream index where drift alarm was raised. |
required |
lookback_window
|
int
|
Maximum history window examined prior to detection. |
300
|
Returns:
| Type | Description |
|---|---|
int
|
Estimated sample index representing drift onset. |
Source code in src/stride/drift/binary_descriptor.py
find_drift_start_threshold
Estimate drift onset by searching for sustained error rate elevation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
detection_idx
|
int
|
Stream index where drift alarm was raised. |
required |
lookback_window
|
int
|
Maximum history window examined prior to detection. |
300
|
Returns:
| Type | Description |
|---|---|
int
|
Estimated sample index representing drift onset. |
Source code in src/stride/drift/binary_descriptor.py
post_process_drift_ends
Post-process a collection of detected drifts to compute peak or recovery timestamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
drift_descriptions
|
list[DriftDescription]
|
Sequence of |
required |
Returns:
| Type | Description |
|---|---|
list[DriftDescription]
|
Updated sequence of descriptions with resolved end indices and peak rates. |
Source code in src/stride/drift/binary_descriptor.py
update
Update detector state with a binary error signal (\(0\) for correct, \(1\) for error).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int | float
|
Binary prediction error indicator. |
required |
Source code in src/stride/drift/binary_descriptor.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
DriftDescription
dataclass
DriftDescription(
error_rate_at_warning=None,
error_rate_at_detection=None,
drift_duration=None,
drift_start_index=None,
drift_end_index=None,
error_rate_at_peak=None,
detected_at=None,
)
Represents characteristics of a detected concept drift event.
Attributes:
| Name | Type | Description |
|---|---|---|
error_rate_at_warning |
float | None
|
Error rate calculated at initial warning threshold. |
error_rate_at_detection |
float | None
|
Error rate when drift alarm was triggered. |
drift_duration |
int | None
|
Total count of stream samples between onset and detection. |
drift_start_index |
int | None
|
Stream sample index pinpointing drift onset. |
drift_end_index |
int | None
|
Stream sample index where drift concluded or stabilized. |
error_rate_at_peak |
float | None
|
Maximum observed error rate across the drift event. |
detected_at |
int | None
|
Stream sample index where detector emitted drift signal. |
DualADWIN
DualADWIN(
delta_warn=0.05,
delta_drift=0.002,
clock=32,
max_buckets=5,
min_window_length=5,
grace_period=10,
)
Dual-threshold ADWIN wrapper providing explicit warning and drift signals.
Maintains two River ADWIN instances internally configured with different
confidence bounds (\(\delta_{\text{warn}} > \delta_{\text{drift}}\)). The more
sensitive instance (\(\delta_{\text{warn}}\)) triggers early warning alerts to
commence lookback caching, while the conservative instance (\(\delta_{\text{drift}}\))
confirms actual concept drift.
Attributes:
| Name | Type | Description |
|---|---|---|
adwin_warn |
Highly sensitive ADWIN instance tracking warning state. |
|
adwin_drift |
Conservative ADWIN instance tracking confirmed drift state. |
Examples:
>>> detector = DualADWIN(delta_warn=0.05, delta_drift=0.002)
>>> detector.update(1.0)
>>> detector.drift_detected
False
Initialize dual-threshold ADWIN detector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_warn
|
float
|
Confidence value for warning threshold. Higher delta implies higher sensitivity. |
0.05
|
delta_drift
|
float
|
Confidence value for confirmed drift threshold. |
0.002
|
clock
|
int
|
Number of incoming samples between subwindow split checks. |
32
|
max_buckets
|
int
|
Maximum number of buckets maintained at each exponential compression tier. |
5
|
min_window_length
|
int
|
Minimum subwindow size required before testing for statistical difference. |
5
|
grace_period
|
int
|
Initial observations processed before drift detection begins. |
10
|
Source code in src/stride/drift/adwin.py
drift_detected
property
Flag indicating whether confirmed drift threshold was exceeded at current step.
estimation
property
Estimated mean error rate of the main drift tracking instance window.
warning_detected
property
Flag indicating whether early warning threshold was exceeded at current step.
update
Update both warning and drift ADWIN instances with a new observation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float | int
|
Input observation value (e.g., binary classification error \(0\) or \(1\)). |
required |