dfr_cusum: Cumulative Sum for Concept Drift Detection (CUSUM) method

View source: R/dfr_cusum.R

dfr_cusumR Documentation

Cumulative Sum for Concept Drift Detection (CUSUM) method

Description

CUSUM is a sequential analysis procedure that accumulates deviations in a monitored signal and raises an alarm when the cumulative evidence exceeds a threshold. In this package, the detector is implemented as an error-based monitor, so it is primarily intended for real concept drift affecting predictive performance. The concept-drift adaptation follows the sequential change-detection literature discussed by Muthukrishnan, Berg, and Wu (2007) doi:10.1109/ICDMW.2007.89.

Usage

dfr_cusum(lambda = 50, delta = 0.005, min_instances = 30)

Arguments

lambda

Detection threshold: a drift is reported when the cumulative sum exceeds it. Lower values react faster at the cost of more false alarms.

delta

Tolerance subtracted at every step, i.e. the increase of the error rate that is still considered acceptable.

min_instances

Minimum number of observations before a drift can be reported.

Details

The detector follows the CusumDM detector of MOA: it accumulates max(0, sum + x - mean - delta), where mean is the running error rate, so it reacts to an increase of the error rate whatever its level. After a drift is reported the statistics restart from scratch. Missing values are treated as correct predictions (0).

Up to version 1.3.0, dfr_cusum() accumulated +1 for every error and -1 for every correct prediction, so it could only detect error rates above 50%.

Value

dfr_cusum object

References

Muthukrishnan, S., Berg, E., and Wu, Y. (2007). Sequential change detection on data streams. In Seventh IEEE International Conference on Data Mining Workshops (ICDMW 2007). doi:10.1109/ICDMW.2007.89

Examples

# Load Heimdall and the synthetic benchmark stream.
library(heimdall)

# Fix the seed for reproducibility.
seed <- 1
set.seed(seed)

# Load the stream and derive a simple binary error-like signal.
data(st_drift_examples)
data <- st_drift_examples$uv_virtual_drift
data$prediction <- st_drift_examples$uv_virtual_drift$serie > 4

# Plot the binary monitored stream used by CUSUM.
plot(x=seq_len(nrow(data)), y=data$prediction)

# Instantiate the CUSUM detector.
model <- dfr_cusum()

# Update the detector sequentially over the binary stream.
detection <- NULL
output <- list(obj=model, drift=FALSE)
for (i in seq_len(nrow(data))){
  output <- update_state(output$obj, data$prediction[i])
  if (output$drift){
    type <- 'drift'
    output$obj <- reset_state(output$obj)
  } else {
    type <- ''
  }
  detection <- rbind(detection, data.frame(idx=i, event=output$drift, type=type))
}

# Print the drift alarms produced by the detector.
detection[detection$type == 'drift',]

# Map the drift alarms back onto the original numeric series.
plot(x=seq_len(nrow(data)), y=data$serie)
for (drift_index in detection[detection$type == 'drift', 'idx']) {
  abline(v=drift_index, col='red', lty=2)
}

heimdall documentation built on Dec. 2, 2026, 5:08 p.m.