-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNN_plot_all.py
92 lines (82 loc) · 2.83 KB
/
RNN_plot_all.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import keras.utils
from keras import optimizers
from keras.models import Sequential, model_from_json, load_model
from keras.layers import Dense, Activation, SimpleRNN
from keras.utils.vis_utils import plot_model
import keras.utils.np_utils
from keras.utils.np_utils import to_categorical
import os
import numpy as np
import datetime
import random
from reader import Reader
from sklearn import metrics
import matplotlib.pyplot as plt
from sklearn import metrics
import RNNHandler
#(1, 'Dataset1', 2, 'RNN_1A')
#(2, 'Dataset2', 2, 'RNN_1A')
#(3, 'Dataset3', 2, 'RNN_1A') !! grafiki
#(4, 'Dataset4', 2, 'RNN_1A') !!! mixed type binary and continous
#(5, 'Dataset5', 3, 'RNN_1B') +categorical
#(6, 'Dataset0', 5, 'RNN_1C') +categorical
dataset_id = 0
dataset_name = 'Dataset0'
num_classes = 5
#RNN_name = 'RNN_1A'
num_epochs = 10
(x_train, y_train), (x_test, y_test) = Reader.getDataset(dataset_id)
#x_train = x_train[0:1000,:]
#y_train = y_train[0:1000]
#x_test = x_test[0:1000,:]
#y_test = y_test[0:1000]
for RNN_name in ['RNN_2C']:
results = {}
#for loss,optimizer in [('mse','sgd')]:#, ('categorical_crossentropy','rmsprop')]: #categorical_crossentropy
#for optimizer in ['sgd', 'rmsprop']:
loss = 'mse'
optimizer = 'sgd'
#optimizer_w_params = optimizers.RMSprop(lr=0.00007)
optimizer_w_params = 'sgd'
RNNmodel = RNNHandler.RNNHandler(RNN_name, num_classes, loss, optimizer_w_params, optimizer)
(res_loss, res_accuracy, res_precision, res_recall, res_fscore) = RNNmodel.fit_and_eval(x_train, y_train, x_test, y_test, num_epochs, dataset_name)
if num_classes == 2:
results[loss + '|' + optimizer] = res_fscore
else:
results[loss + '|' + optimizer] = res_accuracy
title = dataset_name + '.' + RNN_name
metric = 'accuracy'
if num_classes == 2:
metric = 'fscore'
RNNHandler.RNNHandler.plot_results(title, metric, results)
#(6, 'Dataset0', 5, 'RNN_1C') +categorical
#dataset_id = 6
#dataset_name = 'Dataset0'
#num_classes = 5
#RNN_name = 'RNN_1C'
#
#num_epochs = 10
##
#fp_logfile = open('./debug/logfile', "a")
#reader = Reader(fp_logfile, False)
#(x_train, y_train), (x_test, y_test) = reader.getDataNormalized()
#x_train = x_train[0:1000,:]
#y_train = y_train[0:1000]
#x_test = x_test[0:1000,:]
#y_test = y_test[0:1000]
#results = {}
#for loss in ['mse', 'categorical_crossentropy']:
#for optimizer in ['sgd','adagrad', 'rmsprop']:
# RNNmodel = RNNHandler.RNNHandler(RNN_name, num_classes, loss, optimizer)
# #(res_loss, res_accuracy, res_precision, res_recall, res_fscore) = RNNmodel.fit_and_eval(x_train, y_train, x_test, y_test, num_epochs, #dataset_name)
#if num_classes == 2:
# results[loss + '|' + optimizer] = res_fscore
#else:
# results[loss + '|' + optimizer] = res_accuracy
#
#title = dataset_name + '.' + RNN_name
#metric = 'accuracy'
#if num_classes == 2:
#metric = 'fscore'
#RNNHandler.RNNHandler.plot_results(title, metric, results)
#