-
Notifications
You must be signed in to change notification settings - Fork 0
/
exp_ddis.py
78 lines (56 loc) · 2.2 KB
/
exp_ddis.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
import config
import strlearn as sl
import numpy as np
from methods.meta import Meta
from sklearn.base import clone
from methods.MEAN import MEAN
from methods.PREV import PREV
from methods.RFR import RFR
from methods.DSCA import DSCA
from sklearn.metrics import balanced_accuracy_score
from tqdm import tqdm
np.random.seed(1231)
weights = config.str_weights_ddis3()
base_clfs = config.base_clfs()
str_static = config.str_static()
n_chunks=str_static['n_chunks']
reps=10
random_states = np.random.randint(0,100000,reps)
pe_num = 3
meta_cnt = (len(base_clfs) * pe_num ) + len(base_clfs)
results = np.zeros((reps, len(weights), meta_cnt, n_chunks-1, 1))
# reps x weights x (base clfs, prior estims) x chunks x BAC
estim_errs = np.zeros((reps, len(weights), len(base_clfs)*pe_num, n_chunks-1))
t = reps*len(weights)
pbar = tqdm(total=t)
for r in range(reps):
for w_id, w in enumerate(weights):
# new instances of metas
base_metas=[]
base_metas.append(clone(base_clfs[0]))
base_metas.append(clone(base_clfs[1]))
base_metas.append(clone(base_clfs[2]))
base_metas.append(clone(base_clfs[3]))
base_metas.append(clone(base_clfs[4]))
for bc_id, bc in enumerate(base_clfs):
base_metas.append(Meta(clone(bc), MEAN(), criterion='min', border=0.25))
base_metas.append(Meta(clone(bc), PREV(), criterion='min', border=0.25))
# base_metas.append(Meta(clone(bc), (random_state = 123), criterion=c, border=b))
base_metas.append(Meta(clone(bc), DSCA(random_state = 123), criterion='min', border=0.5))
# stream
config = {
**str_static,
**weights[w],
'random_state': random_states[r]
}
stream = sl.streams.StreamGenerator(**config)
# evaluate
eval = sl.evaluators.TestThenTrain(verbose=True, metrics=(balanced_accuracy_score))
eval.process(stream, base_metas)
pbar.update(1)
for bm_i, bm in enumerate(base_metas[3:]):
estim_errs[r, w_id, bm_i] = bm.prior_estimator.calculated_priors_list
results[r, w_id] = eval.scores
np.save('res_e_ddis', results)
np.save('estim_err_ddis', estim_errs)
pbar.close()