DriftDetectionMethod
Description
DriftDetectionMethod model object represents an incremental
concept drift detector that uses the Drift Detection Method [1]. After creating the object,
you can use the detectdrift object
function to update the statistics and check for any drift in the concept data (for example,
failure rate, regression loss, and so on).
DriftDetectionMethod is suitable for incremental concept drift detection. For
drift detection on raw data, see detectdrift for
batch drift detection.
Creation
You can create DriftDetectionMethod by specifying the
DetectionMethod argument as "ddm" in the call to
incrementalConceptDriftDetector.
Properties
Object Input Parameters
Type of alternative hypothesis for determining the drift status, specified as
either 'greater' or 'less'.
Data Types: char
This property is read-only.
Number of standard deviations for drift limit, specified as a nonnegative scalar
value. This is the number of standard deviations the overall test statistic can be
away from the optimal test statistic before the software sets
DriftStatus to 'Drift'.
Data Types: double
This property is read-only.
Type of input data, specified as either 'binary' or
'continuous'.
Data Types: char
This property is read-only.
Number of observations for drift detector warm-up, specified as a nonnegative integer.
Data Types: double
This property is read-only.
Number of standard deviations for warning limit, specified as a nonnegative scalar
value. This is the number of standard deviations the overall test statistic can be
away from the optimal test statistic before the software sets
DriftStatus to 'Warning'.
Data Types: double
Drift Detection Parameters
This property is read-only.
Weighted average of all input data used for training the drift detector, specified as a numeric value.
Data Types: double
This property is read-only.
Number of observations used for training the drift detector, specified as a nonnegative integer value.
Data Types: double
Optimal weighted average detectdrift observes up to the most
current data point, specified as a numeric value.
detectdrift updates
the OptimalMean and OptimalStandardDeviation under any
of these conditions:
When
Alternativeis'greater'andMean+StandardDeviationis less than or equal toOptimalMean+OptimalStandardDeviation.When
Alternativeis'less'andMean-StandardDeviationis greater than or equal toOptimalMean-OptimalStandardDeviation.
Data Types: double
This property is read-only.
Optimal weighted standard deviation detectdrift observes up
to the most current data point, specified as a numeric value.
detectdrift updates
the OptimalMean and OptimalStandardDeviation under any
of these conditions:
When
Alternativeis'greater'andMean+StandardDeviationis less than or equal toOptimalMean+OptimalStandardDeviation.When
Alternativeis'less'andMean-StandardDeviationis greater than or equal toOptimalMean-OptimalStandardDeviation.
Data Types: double
This property is read-only.
Weighted standard deviation of all input data used for training the drift detector, specified as a numeric value.
Data Types: double
Drift Status Parameters
This property is read-only.
Flag indicating whether software detects drift or not, specified as either
1 or 0. Value of 1 means
DriftStatus is 'Drift'.
Data Types: logical
This property is read-only.
Current drift status, specified as 'Stable',
'Warning', or 'Drift'. You can see the
transition in the drift status by comparing DriftStatus and
PreviousDriftStaus.
Data Types: char
This property is read-only.
Flag indicating whether the warm-up period is over or not, specified as
1 (true) or
0(false).
Data Types: logical
This property is read-only.
Drift status prior to the latest training using the most recent batch of data,
specified as 'Stable', 'Warning', or
'Drift'. You can see the transition in the drift status by
comparing DriftStatus and
PreviousDriftStaus.
Data Types: char
This property is read-only.
Flag indicating whether there is warning or not, specified as either
1 or 0. Value of 1 means
DriftStatus is 'Warning'.
Data Types: logical
Object Functions
detectdrift | Update drift detector states and drift status with new data |
reset | Reset incremental concept drift detector |
Examples
Initiate the concept drift detector using the Drift Detection Method (DDM).
incCDDetector = incrementalConceptDriftDetector("ddm");Create a random stream such that for the first 1000 observations, failure rate is 0.1 and after 1000 observations, failure rate increases to 0.6.
rng(1234) % For reproducibility numObservations = 3000; switchPeriod = 1000; for i = 1:numObservations if i <= switchPeriod failurerate = 0.1; else failurerate = 0.6; end X(i) = rand()<failurerate; % Value 1 represents failure end
Preallocate variables for tracking drift status.
status = zeros(numObservations,1); statusname = strings(numObservations,1);
Continuously feed the data to the drift detector and perform incremental drift detection. At each iteration:
Update statistics of the drift detector and monitor for drift using the new data point with
detectdrift. (Note:detectdriftchecks for drift after the warm-up period.)Track and record the drift status for visualization purposes.
When a drift is detected, reset the incremental concept drift detector by using
reset.
for i = 1:numObservations incCDDetector = detectdrift(incCDDetector,X(i)); statusname(i) = string(incCDDetector.DriftStatus); if incCDDetector.DriftDetected status(i) = 2; incCDDetector = reset(incCDDetector); % If drift detected, reset the detector sprintf("Drift detected at Observation #%d. Detector reset.",i) elseif incCDDetector.WarningDetected status(i) = 1; else status(i) = 0; end end
ans = "Drift detected at Observation #1078. Detector reset."
After the change in the failure rate at observation number 1000, detectdrift detects the shift at observation number 1078.
Plot the drift status versus the observation number.
gscatter(1:numObservations,status,statusname,'gyr','*',4,'on',"Observation number","Drift status")

Initiate the concept drift detector using the Drift Detection Method (DDM).
incCDDetector = incrementalConceptDriftDetector("ddm",Alternative="less",WarmupPeriod=100);
Create a random stream such that for the first 1000 observations, failure rate is 0.4 and after 1000 failure rate decreases to 0.1.
rng(1234) % For reproducibility numObservations = 3000; switchPeriod = 1000; for i = 1:numObservations if i <= switchPeriod failurerate = 0.4; else failurerate = 0.125; end X(i) = rand()<failurerate; % Value 1 represents failure end
Preallocate variables for tracking drift status and the optimal mean and optimal standard deviation value.
optmean = zeros(numObservations,1); optstddev = zeros(numObservations,1); status = zeros(numObservations,1); statusname = strings(numObservations,1);
Continuously feed the data to the drift detector and monitor for any potential change. Record the drift status for visualization purposes.
for i = 1:numObservations incCDDetector = detectdrift(incCDDetector,X(i)); statusname(i) = string(incCDDetector.DriftStatus); optmean(i) = incCDDetector.OptimalMean; optstddev(i) = incCDDetector.OptimalStandardDeviation; if incCDDetector.DriftDetected status(i) = 2; incCDDetector = reset(incCDDetector); % If drift detected, reset the detector sprintf("Drift detected at Observation #%d. Detector reset.",i) elseif incCDDetector.WarningDetected status(i) = 1; else status(i) = 0; end end
ans = "Drift detected at Observation #1107. Detector reset."
After the change in the failure rate at observation number 1000, detectdrift detects the shift at observation number 1096.
Plot the change in the optimal mean and optimal standard deviation.
tiledlayout(2,1); ax1 = nexttile; plot(ax1,1:numObservations,optmean) ax2 = nexttile; plot(ax2,1:numObservations,optstddev)

Plot the drift status versus the observation number.
figure(); gscatter(1:numObservations,status,statusname,'gyr','*',4,'on',"Observation number","Drift status")

detectdrift concludes on a warning status for multiple observations before it decides on a drift.
References
[1] Gama, Joao, Pedro Medas, Gladys Castillo, and Pedro P. Rodrigues. “Learning with drift detection.“ In Brazilian symposium on artificial intelligence, pp. 286-295. Berlin, Heidelberg: Springer. 2004, September.
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.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)