-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconceptDrift.R
35 lines (26 loc) · 877 Bytes
/
conceptDrift.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
ad_test_edit <- function(x) {
if (length(unique(x)) == 1) {
return(1)
} else {
return(ad.test(x)$ad[1, 3])
}
}
cdTest <- function(data, alpha = 0.05, freq = 48) {
p <- ncol(data)
freq_win <- (p/freq)/7
win <- p/freq_win
# subset weeks and normalise them
ts_test <- lapply(1:nrow(data),
function(i) lapply(0:(freq_win-1),
function(j) norm_min_max(data[i,((win*j)+1):((win*j)+win)])))
# Anderson-Darling test
ad_pvalues <- sapply(seq_len(length(ts_test)),
function(x) ad_test_edit(ts_test[[x]]))
# EDF change detected or not
n_concept_drifts <- length(which(ad_pvalues < alpha))
if(n_concept_drifts >= ceiling(nrow(data)/2)){
res_cd <- TRUE
} else res_cd <- FALSE
return(list(n_cd = n_concept_drifts,
cd = res_cd))
}