-
Notifications
You must be signed in to change notification settings - Fork 2
/
e_csi.py
executable file
·71 lines (63 loc) · 2.12 KB
/
e_csi.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
#!/usr/bin/env python
"""
Chunk size influence.
"""
import os, arff, warnings
import numpy as np
import helper as h
import strlearn as sl
import matplotlib.pyplot as plt
from tqdm import tqdm
from sklearn import neural_network
from scipy.interpolate import spline
warnings.simplefilter('ignore', DeprecationWarning)
warnings.simplefilter('ignore', ImportWarning)
example = 'csi'
dbname = example
resfolder = 'results'
length = 100000
window = 0
chunk_sizes = [10, 100, 1000]
points_on_plot = 100
evaluate_interval = length // points_on_plot
clfname = "MLP100"
clf = neural_network.MLPClassifier(hidden_layer_sizes=(100,))
controller = sl.controllers.Bare()
# Generation of stream from parameters
streams = [
"generators.RandomRBFGenerator -r 1 -a 20",
"generators.RandomRBFGenerator -r 2 -a 20",
"generators.RandomRBFGenerator -r 3 -a 20"
]
h.generate_stream('ds/%s' % dbname, length, window, streams)
# Experimental loop
colors = 'rgbcmyk'
with open('ds/%s.arff' % dbname, 'r') as stream:
dataset = arff.load(stream)
data = np.array(dataset['data'])
X = data[:, :-1].astype(np.float)
y = data[:, -1]
fig, ax = plt.subplots(len(chunk_sizes) + 1,
figsize=(4,2.5*(len(chunk_sizes)+1)))
ax[0].set_ylim([.4, 1])
ax[0].set_xticks([])
ax[0].set_yticks([])
i = 1
for chunk_size in tqdm(chunk_sizes,ascii=True, desc="CHS"):
filename = '%s/%s_chunk_%i.csv' % (resfolder, example, chunk_size)
learner = sl.Learner(X, y, clf,
evaluate_interval=evaluate_interval,
chunk_size=chunk_size,
controller=controller)
learner.run()
learner.serialize(filename)
ax[i].plot(learner.score_points,
learner.scores, label=chunk_size, c = colors[i-1])
ax[i].set_title("chunk of %i samples" % chunk_size)
ax[i].set_ylim([.4, 1])
ax[i].set_xticks([])
ax[i].set_yticks([])
ax[0].plot(learner.score_points,
learner.scores, label=chunk_size, c = colors[i-1])
i += 1
plt.savefig('figures/%s.png' % example)