-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment_real_cdde.py
64 lines (52 loc) · 1.75 KB
/
experiment_real_cdde.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
import os
import strlearn as sl
import problexity as px
import numpy as np
from detectors.CDDE import CDDE
dir = 'real_streams/'
files = [
'covtypeNorm-1-2vsAll-pruned.arff',
'electricity.csv',
'poker-lsn-1-2vsAll-pruned.arff',
'INSECTS-abrupt_imbalanced_norm.arff',
'INSECTS-gradual_imbalanced_norm.arff',
'INSECTS-incremental_imbalanced_norm.arff'
]
chunks = 2000
chunk_size = 250
measures = np.array([getattr(px.classification, n)
for n in px.classification.__all__])
metric_mask = np.ones_like(measures).astype(bool)
metric_mask[4] = False
measures = measures[metric_mask]
th = 0.75
c=0
for f in files:
print(f)
if f.split('.')[0] == 'electricity':
data = np.loadtxt('%s/%s' % (dir, f), delimiter=',',skiprows=1, dtype=object)
data[data=='UP'] = 1
data[data=='DOWN'] = 0
data = data.astype(float)
np.save('%s/electricity.npy' % dir, data)
stream = sl.streams.NPYParser('%s/electricity.npy' % dir, chunk_size=chunk_size, n_chunks=chunks)
else:
stream = sl.streams.ARFFParser('%s/%s' % (dir, f), chunk_size=chunk_size, n_chunks=chunks)
if f.split('-')[0]=='poker':
cdde = CDDE(measures=measures, treshold=1.5)
else:
cdde = CDDE(measures=measures, treshold=th)
for chunk in range(chunks):
try:
X, y = stream.get_chunk()
except:
print(chunk, 'break')
break
if len(np.unique(y))!=2:
print('continue')
continue
cdde.feed(X, y)
r = np.concatenate((np.array(cdde.drift).reshape(-1, 1), np.array(cdde.supports).reshape(-1, 1)), axis=1)
print(r[:100])
np.save('real_streams_res/cdde_%s' % f.split('.')[0], r)
c+=1