Create a random stream such that the first 1000 observations come from a normal distribution with mean 2 and standard deviation 0.75 and the next 1000 come from a normal distribution with mean 4 and standard deviation 1. In an incremental drift detection application, access to data stream and model update would happen consecutively. One would not collect the data first and then feed into the model. However, for the purpose of clarification, this example demonstrates the simulation of data separately.
Initiate the incremental concept drift detector. Utilize the Hoeffding's bound method with exponential moving average method (EWMA). Specify the input type as continuous, a warmup of 50 observations, and an estimation period of 50 observations.
incCDDetector =
HoeffdingDriftDetectionMethod
PreviousDriftStatus: 'Stable'
DriftStatus: 'Stable'
IsWarm: 0
NumTrainingObservations: 0
Alternative: 'greater'
InputType: 'continuous'
TestMethod: 'ewma'
incDDetector
is a HoeffdingDriftDetectionMethod
object. When you first create the object, properties such as DriftStatus
, IsWarm
, CutMean
, and NumTrainingObservations
are at their initial state. detectdrift
updates them as you feed the data incrementally and monitor for drift.
Preallocate the batch size and the variables to record drift status and statistics.
Simulate the data stream of one observation at a time and perform incremental drift detection. At each iteration:
Monitor for drift using the new data with detectdrift
.
Track and record the drift status for visualization purposes.
When a drift is detected, reset the incremental concept drift detector by using the function reset
.
ans =
"Warning detected at observation #1019."
ans =
"Warning detected at observation #1020."
ans =
"Warning detected at observation #1021."
ans =
"Warning detected at observation #1022."
ans =
"Drift detected at observation #1023. Detector reset."
Plot the drift status versus the data observation number.