-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_compare_all.py
94 lines (72 loc) · 2.94 KB
/
exp_compare_all.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from pymfe.mfe import MFE
import numpy as np
from sklearn import clone
from sklearn.svm import OneClassSVM
import strlearn as sl
from mcs import MCS
from sklearn.neural_network import MLPClassifier
from sklearn.naive_bayes import GaussianNB
from strlearn.evaluators import TestThenTrain
from tqdm import tqdm
from skmultiflow.trees import HoeffdingTree
np.random.seed(122)
# config
n_chunks = 500
chunk_size = 250
recurring = True
n_features = [10,20,30]
n_drifts= [5,7,9,11]
random_states = np.random.randint(100, 1000000, 10)
measures_names = ['mean', 'median', 't_mean', 'gravity',
'w_lambda', 'p_trace', 'can_cor', 'lh_trace',
'roy_root', 'cov', 'cor']
mfe = MFE(groups="statistical", features=measures_names, summary=['mean'])
m_oc = 25
min_concept_len = 5
thresholds = [2.2, 2.0, 1.6]
base_oneclass=OneClassSVM(kernel='rbf')
# experiment
n_methods=6
res_clf = np.zeros((len(n_features), len(n_drifts), len(random_states), n_methods, n_chunks-1))
pbar = tqdm(total=len(n_features)*len(n_drifts)*len(random_states))
for n_f_id, n_f in enumerate(n_features):
for d_id, d in enumerate(n_drifts):
for rs_id, rs in enumerate(random_states):
config = {
'n_drifts': d,
'n_chunks': n_chunks,
'chunk_size': chunk_size,
'n_features': n_f,
'n_informative': int(0.3*n_f),
'n_redundant': 0,
'recurring': True,
'concept_sigmoid_spacing': 999,
'random_state': rs
}
stream = sl.streams.StreamGenerator(**config)
methods = [
GaussianNB(),
MCS(mfe, base_clf=GaussianNB(),
base_oneclass=clone(base_oneclass),
threshold=thresholds[n_f_id],
max_oc=m_oc,
min_concept_len=min_concept_len),
MLPClassifier(),
MCS(mfe, base_clf=MLPClassifier(),
base_oneclass=clone(base_oneclass),
threshold=thresholds[n_f_id],
max_oc=m_oc,
min_concept_len=min_concept_len),
HoeffdingTree(),
MCS(mfe, base_clf=HoeffdingTree(),
base_oneclass=clone(base_oneclass),
threshold=thresholds[n_f_id],
max_oc=m_oc,
min_concept_len=min_concept_len),
]
evaluator = TestThenTrain(metrics=sl.metrics.balanced_accuracy_score, verbose=True)
evaluator.process(stream, methods)
pbar.update(1)
print(evaluator.scores.shape)
res_clf[n_f_id, d_id, rs_id] = evaluator.scores[:,:,0]
np.save('results_v4/res_compare_all.npy', res_clf)