detectdrift
Syntax
Description
updates the internal statistics and the drift status with new data in IncCDDetector
= detectdrift(IncCDDetector
,X
)X
and returns the modified detector IncCDDetector
.
detectdrift
updates the drift status only if the
IsWarm
property is true
(or 1).
updates IncCDDetector
= detectdrift(IncCDDetector
,X
,Weights=W
)IncCDDetector
also using the observation weights in
W
.
You can use the Weights
argument for the Drift Detection Method
(DDM) only. Specify "DDM"
for the DetectionMethod
argument in the call to incrementalConceptDriftDetector
.
Examples
Perform Drift Detection on Data Stream
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.
rng(1234) % For reproducibility numObservations = 3000; switchPeriod1 = 1000; X = zeros([numObservations 1]); for i = 1:numObservations if i <= switchPeriod1 X(i) = normrnd(2,0.75); else X(i) = normrnd(4,1); end end
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 = incrementalConceptDriftDetector("hddmw",InputType="continuous", ... WarmupPeriod=50,EstimationPeriod=50)
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.
status = zeros([numObservations 1]); statusname = strings([numObservations 1]);
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
.
for i = 1:numObservations incCDDetector = detectdrift(incCDDetector,X(i)); if incCDDetector.DriftDetected status(i) = 2; statusname(i) = string(incCDDetector.DriftStatus); incCDDetector = reset(incCDDetector); % If drift detected, reset the detector sprintf("Drift detected at observation #%d. Detector reset.",i) elseif incCDDetector.WarningDetected status(i) = 1; statusname(i) = string(incCDDetector.DriftStatus); sprintf("Warning detected at observation #%d.",i) else status(i) = 0; statusname(i) = string(incCDDetector.DriftStatus); end end
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.
gscatter(1:numObservations,status,statusname,'gyr','*',5,'on',"Number of observations","Drift status")
Input Arguments
IncCDDetector
— Incremental concept drift detector
DriftDetectionMethod
| HoeffdingDriftDetectionMethod
Incremental concept drift detector, specified as either DriftDetectionMethod
or HoeffdingDriftDetectionMethod
object. For more information on these
objects and their properties, see the corresponding reference pages.
X
— Input data
n-by-1 vector of real numbers | logical vector | vector of 0s and 1s
Input data, specified as an n-by-1 vector of real numbers, where n is the number of observations.
If the
InputType
value in the call toincrementalConceptDriftDetector
is"continuous"
, thenX
must be a vector of real-valued numbers.If the
InputType
value in the call toincrementalConceptDriftDetector
is"binary"
, thenX
can be a logical vector or vector of 0s and 1s.
Data Types: single
| double
| logical
W
— Observation weights
n-by-1 vector of real numbers
Observation weights, specified as an n-by-1 vector of real
numbers, where n is the number of observations.
W
must have the same number of elements as
X
.
You cannot use the Weights
argument for the Hoeffding's Bounds
Drift Detection Method using exponentially weighted moving averages (HDDMW). To use
observation weights, specify "ddm"
or "hddma"
as
the DetectionMethod
in the call to incrementalConceptDriftDetector
.
Data Types: single
| double
Version History
Introduced in R2022a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)