-
Notifications
You must be signed in to change notification settings - Fork 0
/
experiment_real.py
58 lines (47 loc) · 1.56 KB
/
experiment_real.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
import os
import strlearn as sl
import problexity as px
import numpy as np
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]
for f in files:
print(f)
c = [[] for i in range(len(measures))]
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)
for chunk in range(chunks):
try:
X, y = stream.get_chunk()
print(X.shape)
break
except:
print(chunk, 'break')
break
if len(np.unique(y))!=2:
print('continue')
continue
for m_id, m in enumerate(measures):
c[m_id].append(m(X, y))
np.save('real_streams_res/%s' % f.split('.')[0], np.array(c))
# print(c)