-
Notifications
You must be signed in to change notification settings - Fork 0
/
MOA_Data.py
36 lines (29 loc) · 905 Bytes
/
MOA_Data.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
import os
from sklearn.naive_bayes import GaussianNB
from strlearn.streams import ARFFParser
from sklearn.metrics import accuracy_score
import matplotlib.pyplot as plt
from scipy.signal import medfilt
streams = os.listdir('data/moa')
streams.remove('.DS_Store')
print(streams)
chunks = 500
fig, ax = plt.subplots(4,3,figsize=(12,7), sharex=True, sharey=True)
ax = ax.ravel()
for s_id, s in enumerate(streams):
data = ARFFParser('data/moa/%s' % s)
clf = GaussianNB()
scores = []
for c in range(chunks):
X, y = data.get_chunk()
if c==0:
clf.fit(X, y)
else:
scores.append(accuracy_score(y, clf.predict(X)))
ax[s_id].plot(medfilt(scores,11))
ax[s_id].grid(ls=':')
ax[s_id].set_title(s.split('.')[0])
if s_id in [0,3,6,9]:
ax[s_id].set_ylabel('accuracy')
plt.tight_layout()
plt.savefig('foo.png')