| dfr_kswin | R Documentation |
KSWIN applies a Kolmogorov-Smirnov test between a recent window and a reference sample drawn from older observations. In this package, the method is primarily used for virtual concept drift, because it monitors distributional changes in a numeric feature stream. The method follows Raab et al. (2020) doi:10.1016/j.neucom.2019.11.111.
dfr_kswin(
target_feat = NULL,
window_size = 300,
stat_size = 100,
alpha = 1e-04,
window_type = "sliding",
monitoring_step = 1,
exact = NULL,
data = NULL,
seed = NULL
)
target_feat |
Feature to be monitored. |
window_size |
Size of the sliding window. It must be greater than
|
stat_size |
Size of the statistic window |
alpha |
Probability for the test statistic of the Kolmogorov-Smirnov-Test The alpha parameter is very sensitive, therefore should be set below 0.01. |
window_type |
Window policy. |
monitoring_step |
Number of observations between two consecutive tests. The default ( |
exact |
Passed to |
data |
Already collected data to avoid cold start. |
seed |
Seed of the random number stream used to subsample the reference
window. When |
The reference window is randomly subsampled to stat_size
observations. The detector keeps its own random number stream, so it does not
change the global random state while it runs; set seed (or call
base::set.seed() before creating the detector) for reproducible results.
A drift requires both a significant p-value and a KS statistic above
sqrt(-log(alpha) / stat_size), as defined by Raab et al. Missing
observations are skipped instead of being imputed.
dfr_kswin object
Raab, C., Heusinger, M., and Schleif, F.-M. (2020). Reactive soft prototype computing for concept drift streams. Neurocomputing, 416, 340-351. doi:10.1016/j.neucom.2019.11.111
# Load Heimdall and the synthetic univariate stream.
library(heimdall)
# Fix the seed for reproducibility.
seed <- 1
set.seed(seed)
# Load the numeric stream used by the detector.
data(st_drift_examples)
serie <- st_drift_examples$uv_virtual_drift
# Plot the monitored variable before detection.
plot(x=seq_len(nrow(serie)), y=serie$serie)
# Instantiate KSWIN with explicit window parameters.
model <- dfr_kswin(target_feat='serie', window_size=100, stat_size=50)
# Update the detector sequentially and store the alarm positions.
detection <- NULL
output <- list(obj=model, drift=FALSE)
for (i in seq_len(nrow(serie))){
output <- update_state(output$obj, serie$serie[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 points where KSWIN raised drift alarms.
detection[detection$type == 'drift',]
# Overlay the detected drifts on the original stream.
plot(x=seq_len(nrow(serie)), y=serie$serie)
for (drift_index in detection[detection$type == 'drift', 'idx']) {
abline(v=drift_index, col='red', lty=2)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.