diff --git a/LSTMHandler.py b/LSTMHandler.py index 35b8592..3305a82 100644 --- a/LSTMHandler.py +++ b/LSTMHandler.py @@ -42,7 +42,7 @@ def MyMetrics(y_true, y_pred): class LSTMHandler: results_directory = './LSTMresults' - models_directory = './LSTMmodels' + models_directory = './LSTMmodels/' def __init__(self, model_name, num_categories, loss, optimizer): # GET THE MODEL @@ -88,7 +88,8 @@ def fit_and_eval(self, x_train, y_train, x_test, y_test, nb_epoch, dataset_name) res_recall.append(recall) res_fscore.append(fscore) self.write_result(str(i) +'|'+ str(loss) +'|'+ str(accuracy) +'|'+ str(precision) +'|'+ str(recall) +'|'+ str(fscore)) - + self.model.save(self.models_directory + 'full_models/' + dataset_name + '.' + self.model_name + '.epoch' + str(i) + '.h5') + self.model.save(self.models_directory + 'full_models/' + dataset_name + '.' + self.model_name + '.h5') return (res_loss, res_accuracy, res_precision, res_recall, res_fscore) diff --git a/LSTM_2C.py b/LSTM_2C.py new file mode 100644 index 0000000..a00a1ba --- /dev/null +++ b/LSTM_2C.py @@ -0,0 +1,27 @@ + +from keras.models import Sequential +from keras.layers import Dense, Activation, LSTM +from keras.utils.vis_utils import plot_model +import os +import numpy as np +from reader import Reader + + +length = Reader.getInputShape() + +model = Sequential() + +#EXPECTS INPUT AS (nb_sample, timesteps, nb_features), where nb_sample=1 (batch_size = 1), timesteps = 1 and nb_features = length + +#model.add(Dense(40, input_dim = 12, init='uniform', activation='relu')) +model.add(LSTM(units=50, input_shape=(1,length), batch_input_shape=(1,1,length), recurrent_initializer='random_uniform', kernel_initializer='random_uniform', activation='sigmoid', return_sequences=True, stateful=True)) +model.add(LSTM(units=50, recurrent_initializer='random_uniform', kernel_initializer='random_uniform', activation='sigmoid', stateful=True)) +model.add(Dense(5, kernel_initializer='random_uniform', activation = 'softmax')) + + +model.summary() +plot_model(model, to_file='./LSTMmodels/LSTM_2C.png', show_shapes=True) +fp = open('./LSTMmodels/LSTM_2C.json', 'w') +fp.write(model.to_json()) +fp.close() + diff --git a/LSTM_plot_all.py b/LSTM_plot_all.py index 42653de..bd0d92d 100644 --- a/LSTM_plot_all.py +++ b/LSTM_plot_all.py @@ -22,9 +22,9 @@ #(4, 'Dataset4', 2, 'RNN_1A') #(5, 'Dataset5', 3, 'RNN_1B') #(6, 'Dataset0', 5, 'RNN_1C') -dataset_id = 3 -dataset_name = 'Dataset3' -num_classes = 2 +dataset_id = 0 +dataset_name = 'Dataset0' +num_classes = 5 #RNN_name = 'RNN_1A' num_epochs = 10 @@ -35,9 +35,9 @@ #x_test = x_test[0:1000,:] #y_test = y_test[0:1000] -for LSTM_name in ['LSTM_1.2A','LSTM_2.2A', 'LSTM_3.2A']: +for LSTM_name in ['LSTM_2C']: results = {} - for loss,optimizer in [('binary_crossentropy','rmsprop')]: #categorical_crossentropy + for loss,optimizer in [('mse','sgd')]: #categorical_crossentropy #for optimizer in ['sgd', 'rmsprop']: LSTMmodel = LSTMHandler.LSTMHandler(LSTM_name, num_classes, loss, optimizer) (res_loss, res_accuracy, res_precision, res_recall, res_fscore) = LSTMmodel.fit_and_eval(x_train, y_train, x_test, y_test, num_epochs, dataset_name) diff --git a/LSTMmodels/LSTM_2C.json b/LSTMmodels/LSTM_2C.json new file mode 100644 index 0000000..01b2d1c --- /dev/null +++ b/LSTMmodels/LSTM_2C.json @@ -0,0 +1 @@ +{"config": [{"config": {"recurrent_activation": "hard_sigmoid", "recurrent_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "implementation": 0, "bias_constraint": null, "unit_forget_bias": true, "units": 50, "trainable": true, "activation": "sigmoid", "return_sequences": true, "use_bias": true, "name": "lstm_1", "bias_initializer": {"config": {}, "class_name": "Zeros"}, "recurrent_regularizer": null, "dropout": 0.0, "recurrent_dropout": 0.0, "kernel_regularizer": null, "dtype": "float32", "bias_regularizer": null, "activity_regularizer": null, "unroll": false, "stateful": true, "batch_input_shape": [1, 1, 79], "kernel_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "kernel_constraint": null, "recurrent_constraint": null, "go_backwards": false}, "class_name": "LSTM"}, {"config": {"recurrent_activation": "hard_sigmoid", "recurrent_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "implementation": 0, "bias_constraint": null, "unit_forget_bias": true, "units": 50, "trainable": true, "activation": "sigmoid", "return_sequences": false, "dropout": 0.0, "name": "lstm_2", "bias_initializer": {"config": {}, "class_name": "Zeros"}, "recurrent_regularizer": null, "use_bias": true, "recurrent_dropout": 0.0, "kernel_regularizer": null, "bias_regularizer": null, "activity_regularizer": null, "unroll": false, "stateful": true, "kernel_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "kernel_constraint": null, "recurrent_constraint": null, "go_backwards": false}, "class_name": "LSTM"}, {"config": {"trainable": true, "use_bias": true, "bias_constraint": null, "units": 5, "activation": "softmax", "bias_regularizer": null, "activity_regularizer": null, "name": "dense_1", "kernel_regularizer": null, "kernel_initializer": {"config": {"seed": null, "maxval": 0.05, "minval": -0.05}, "class_name": "RandomUniform"}, "kernel_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}}, "class_name": "Dense"}], "backend": "theano", "class_name": "Sequential", "keras_version": "2.0.3"} \ No newline at end of file diff --git a/LSTMmodels/LSTM_2C.png b/LSTMmodels/LSTM_2C.png new file mode 100644 index 0000000..f25587b Binary files /dev/null and b/LSTMmodels/LSTM_2C.png differ diff --git a/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C new file mode 100644 index 0000000..0d0c161 --- /dev/null +++ b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C @@ -0,0 +1,60 @@ +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.14650396882|0.581|0|0|0 +2|0.134933630332|0.581|0|0|0 +3|0.12807858073|0.581|0|0|0 +4|0.125045746896|0.581|0|0|0 +5|0.123950693227|0.581|0|0|0 +6|0.123648752145|0.581|0|0|0 +7|0.123634647191|0.581|0|0|0 +8|0.123708837941|0.581|0|0|0 +9|0.123797330961|0.581|0|0|0 +10|0.123875424441|0.581|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.146884530544|0.579|0|0|0 +2|0.135687147945|0.579|0|0|0 +3|0.128945879199|0.579|0|0|0 +4|0.125824560031|0.579|0|0|0 +5|0.124595511615|0.579|0|0|0 +6|0.124180880323|0.579|0|0|0 +7|0.124085704312|0.579|0|0|0 +8|0.12410484181|0.579|0|0|0 +9|0.124156942427|0.579|0|0|0 +10|0.124211117879|0.579|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.150555812597|0.55|0|0|0 +2|0.142311920874|0.55|0|0|0 +3|0.136620218471|0.55|0|0|0 +4|0.133332525082|0.55|0|0|0 +5|0.131608594321|0.55|0|0|0 +6|0.130735595852|0.55|0|0|0 +7|0.130294553764|0.55|0|0|0 +8|0.130069818463|0.55|0|0|0 +9|0.129955085322|0.55|0|0|0 +10|0.129897934154|0.55|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|nan|0.548665297741|0|0|0 +2|nan|0.548665297741|0|0|0 +3|nan|0.548665297741|0|0|0 +4|nan|0.548665297741|0|0|0 +5|nan|0.548665297741|0|0|0 +6|nan|0.548665297741|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.132268971939|0.536852063103|0|0|0 +2|0.127221430943|0.536852063103|0|0|0 +3|0.0402869192958|0.90296597201|0|0|0 +4|0.013252615212|0.971286274728|0|0|0 +5|0.00871043029935|0.978256030717|0|0|0 +6|0.00715632640869|0.9796193762|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.131039403329|0.544940222032|0|0|0 +2|0.0857365173791|0.654608774552|0|0|0 +3|0.0308658724279|0.924130017079|0|0|0 +4|0.0121295026073|0.97045794193|0|0|0 +5|0.00885947539087|0.976542485056|0|0|0 +6|0.00754022111713|0.978730785653|0|0|0 diff --git a/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch1.h5 b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch1.h5 new file mode 100644 index 0000000..30d1720 Binary files /dev/null and b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch1.h5 differ diff --git a/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch2.h5 b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch2.h5 new file mode 100644 index 0000000..9e7e7c2 Binary files /dev/null and b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch2.h5 differ diff --git a/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch3.h5 b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch3.h5 new file mode 100644 index 0000000..84606c5 Binary files /dev/null and b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch3.h5 differ diff --git a/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch4.h5 b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch4.h5 new file mode 100644 index 0000000..89bc9c2 Binary files /dev/null and b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch4.h5 differ diff --git a/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch5.h5 b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch5.h5 new file mode 100644 index 0000000..7b98d4b Binary files /dev/null and b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch5.h5 differ diff --git a/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch6.h5 b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch6.h5 new file mode 100644 index 0000000..c12a04d Binary files /dev/null and b/LSTMmodels/full_models/Dataset0.LSTM_2C/Dataset0.LSTM_2C.epoch6.h5 differ diff --git a/LSTMresults/Dataset0.LSTM_2C b/LSTMresults/Dataset0.LSTM_2C new file mode 100644 index 0000000..0d0c161 --- /dev/null +++ b/LSTMresults/Dataset0.LSTM_2C @@ -0,0 +1,60 @@ +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.14650396882|0.581|0|0|0 +2|0.134933630332|0.581|0|0|0 +3|0.12807858073|0.581|0|0|0 +4|0.125045746896|0.581|0|0|0 +5|0.123950693227|0.581|0|0|0 +6|0.123648752145|0.581|0|0|0 +7|0.123634647191|0.581|0|0|0 +8|0.123708837941|0.581|0|0|0 +9|0.123797330961|0.581|0|0|0 +10|0.123875424441|0.581|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.146884530544|0.579|0|0|0 +2|0.135687147945|0.579|0|0|0 +3|0.128945879199|0.579|0|0|0 +4|0.125824560031|0.579|0|0|0 +5|0.124595511615|0.579|0|0|0 +6|0.124180880323|0.579|0|0|0 +7|0.124085704312|0.579|0|0|0 +8|0.12410484181|0.579|0|0|0 +9|0.124156942427|0.579|0|0|0 +10|0.124211117879|0.579|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.150555812597|0.55|0|0|0 +2|0.142311920874|0.55|0|0|0 +3|0.136620218471|0.55|0|0|0 +4|0.133332525082|0.55|0|0|0 +5|0.131608594321|0.55|0|0|0 +6|0.130735595852|0.55|0|0|0 +7|0.130294553764|0.55|0|0|0 +8|0.130069818463|0.55|0|0|0 +9|0.129955085322|0.55|0|0|0 +10|0.129897934154|0.55|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|nan|0.548665297741|0|0|0 +2|nan|0.548665297741|0|0|0 +3|nan|0.548665297741|0|0|0 +4|nan|0.548665297741|0|0|0 +5|nan|0.548665297741|0|0|0 +6|nan|0.548665297741|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.132268971939|0.536852063103|0|0|0 +2|0.127221430943|0.536852063103|0|0|0 +3|0.0402869192958|0.90296597201|0|0|0 +4|0.013252615212|0.971286274728|0|0|0 +5|0.00871043029935|0.978256030717|0|0|0 +6|0.00715632640869|0.9796193762|0|0|0 +LSTM_2C Dataset0 Loss:mse Optimizer:sgd Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|0.131039403329|0.544940222032|0|0|0 +2|0.0857365173791|0.654608774552|0|0|0 +3|0.0308658724279|0.924130017079|0|0|0 +4|0.0121295026073|0.97045794193|0|0|0 +5|0.00885947539087|0.976542485056|0|0|0 +6|0.00754022111713|0.978730785653|0|0|0 diff --git a/RNNHandler.py b/RNNHandler.py index 8553c86..bbb96ac 100644 --- a/RNNHandler.py +++ b/RNNHandler.py @@ -44,7 +44,7 @@ class RNNHandler: results_directory = './RNNresults' models_directory = './RNNmodels' - def __init__(self, model_name, num_categories, loss, optimizer): + def __init__(self, model_name, num_categories, loss, optimizer, optimizer_name): # GET THE MODEL fp_model = open(os.path.join(self.models_directory, model_name + '.json'), 'r') model_str = fp_model.read() @@ -56,11 +56,12 @@ def __init__(self, model_name, num_categories, loss, optimizer): self.num_categories = num_categories self.loss = loss self.optimizer = optimizer + self.optimizer_name = optimizer_name def fit_and_eval(self, x_train, y_train, x_test, y_test, nb_epoch, dataset_name): #batch_size is always 1 and shuffle is always False, so we don't pass them as parameters self.results_file = os.path.join(self.results_directory, dataset_name + '.' + self.model_name) - self.write_result(self.model_name + ' ' + dataset_name + ' Loss:' + self.loss + ' Optimizer:' + self.optimizer + ' Dropout:No') + self.write_result(self.model_name + ' ' + dataset_name + ' Loss:' + self.loss + ' Optimizer:' + self.optimizer_name + ' Dropout:No') self.write_result('Epoch|Loss|Accuracy|Precision|Recall|Fscore') res_loss = [] res_accuracy = [] diff --git a/RNN_2.2C.py b/RNN_2.2C.py new file mode 100644 index 0000000..2deb162 --- /dev/null +++ b/RNN_2.2C.py @@ -0,0 +1,27 @@ + +from keras.models import Sequential +from keras.layers import Dense, Activation, SimpleRNN +from keras.utils.vis_utils import plot_model +import os +import numpy as np +from reader import Reader + + +length = Reader.getInputShape() + +model = Sequential() + +#EXPECTS INPUT AS (nb_sample, timesteps, nb_features), where nb_sample=1 (batch_size = 1), timesteps = 1 and nb_features = length + +#model.add(Dense(40, input_dim = 12, init='uniform', activation='relu')) +model.add(SimpleRNN(units=50, input_shape=(1,length), batch_input_shape=(1,1,length), recurrent_initializer='random_uniform', kernel_initializer='random_uniform', activation='sigmoid', return_sequences=True, stateful=True)) +model.add(SimpleRNN(units=50, recurrent_initializer='random_uniform', kernel_initializer='random_uniform', activation='sigmoid', stateful=True)) +model.add(Dense(5, kernel_initializer='random_uniform', activation = 'softmax')) + + +model.summary() +plot_model(model, to_file='./RNNmodels/RNN_2.2C.png', show_shapes=True) +fp = open('./RNNmodels/RNN_2.2C.json', 'w') +fp.write(model.to_json()) +fp.close() + diff --git a/RNN_plot_all.py b/RNN_plot_all.py index b34fd9a..bc1b047 100644 --- a/RNN_plot_all.py +++ b/RNN_plot_all.py @@ -1,4 +1,5 @@ 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 @@ -27,7 +28,7 @@ num_classes = 5 #RNN_name = 'RNN_1A' -num_epochs = 20 +num_epochs = 10 (x_train, y_train), (x_test, y_test) = Reader.getDataset(dataset_id) #x_train = x_train[0:1000,:] @@ -37,14 +38,18 @@ for RNN_name in ['RNN_2C']: results = {} - for loss,optimizer in [('mse','sgd')]:#, ('categorical_crossentropy','rmsprop')]: #categorical_crossentropy + #for loss,optimizer in [('mse','sgd')]:#, ('categorical_crossentropy','rmsprop')]: #categorical_crossentropy #for optimizer in ['sgd', '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 + 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' diff --git a/RNNmodels/RNN_2.2C.json b/RNNmodels/RNN_2.2C.json new file mode 100644 index 0000000..5c0ae6d --- /dev/null +++ b/RNNmodels/RNN_2.2C.json @@ -0,0 +1 @@ +{"config": [{"config": {"kernel_regularizer": null, "units": 50, "bias_regularizer": null, "batch_input_shape": [1, 1, 79], "bias_constraint": null, "recurrent_regularizer": null, "stateful": true, "dtype": "float32", "recurrent_dropout": 0.0, "implementation": 0, "recurrent_constraint": null, "use_bias": true, "kernel_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}, "return_sequences": true, "activity_regularizer": null, "name": "simple_rnn_1", "unroll": false, "activation": "sigmoid", "trainable": true, "go_backwards": false, "kernel_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "dropout": 0.0, "recurrent_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}}, "class_name": "SimpleRNN"}, {"config": {"kernel_regularizer": null, "units": 50, "bias_regularizer": null, "bias_constraint": null, "recurrent_regularizer": null, "stateful": true, "recurrent_dropout": 0.0, "implementation": 0, "recurrent_constraint": null, "use_bias": true, "kernel_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}, "return_sequences": false, "activity_regularizer": null, "name": "simple_rnn_2", "unroll": false, "activation": "sigmoid", "trainable": true, "go_backwards": false, "kernel_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "dropout": 0.0, "recurrent_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}}, "class_name": "SimpleRNN"}, {"config": {"kernel_regularizer": null, "units": 5, "bias_regularizer": null, "bias_constraint": null, "name": "dense_1", "activity_regularizer": null, "activation": "softmax", "trainable": true, "kernel_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "use_bias": true, "kernel_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}}, "class_name": "Dense"}], "class_name": "Sequential", "keras_version": "2.0.3", "backend": "theano"} \ No newline at end of file diff --git a/RNNmodels/RNN_2.2C.png b/RNNmodels/RNN_2.2C.png new file mode 100644 index 0000000..ccdc265 Binary files /dev/null and b/RNNmodels/RNN_2.2C.png differ diff --git a/RNNmodels/RNN_2C.json b/RNNmodels/RNN_2C.json index 521277a..67f8f76 100644 --- a/RNNmodels/RNN_2C.json +++ b/RNNmodels/RNN_2C.json @@ -1 +1 @@ -{"keras_version": "2.0.3", "config": [{"config": {"stateful": true, "trainable": true, "bias_regularizer": null, "recurrent_regularizer": null, "return_sequences": true, "use_bias": true, "name": "simple_rnn_1", "activity_regularizer": null, "unroll": false, "dtype": "float32", "activation": "relu", "batch_input_shape": [1, 1, 79], "units": 50, "bias_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "kernel_regularizer": null, "recurrent_initializer": {"config": {"maxval": 0.05, "minval": -0.05, "seed": null}, "class_name": "RandomUniform"}, "go_backwards": false, "recurrent_constraint": null, "recurrent_dropout": 0.0, "implementation": 0, "dropout": 0.0, "kernel_initializer": {"config": {"maxval": 0.05, "minval": -0.05, "seed": null}, "class_name": "RandomUniform"}, "kernel_constraint": null}, "class_name": "SimpleRNN"}, {"config": {"stateful": true, "trainable": true, "bias_regularizer": null, "recurrent_regularizer": null, "return_sequences": false, "use_bias": true, "name": "simple_rnn_2", "activity_regularizer": null, "unroll": false, "activation": "relu", "units": 50, "bias_constraint": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "kernel_regularizer": null, "recurrent_initializer": {"config": {"maxval": 0.05, "minval": -0.05, "seed": null}, "class_name": "RandomUniform"}, "go_backwards": false, "recurrent_constraint": null, "recurrent_dropout": 0.0, "implementation": 0, "dropout": 0.0, "kernel_initializer": {"config": {"maxval": 0.05, "minval": -0.05, "seed": null}, "class_name": "RandomUniform"}, "kernel_constraint": null}, "class_name": "SimpleRNN"}, {"config": {"bias_constraint": null, "name": "dense_1", "trainable": true, "bias_regularizer": null, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "use_bias": true, "units": 5, "activity_regularizer": null, "kernel_regularizer": null, "kernel_initializer": {"config": {"maxval": 0.05, "minval": -0.05, "seed": null}, "class_name": "RandomUniform"}, "activation": "softmax", "kernel_constraint": null}, "class_name": "Dense"}], "backend": "theano", "class_name": "Sequential"} \ No newline at end of file +{"keras_version": "2.0.3", "config": [{"config": {"return_sequences": true, "use_bias": true, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "units": 50, "dropout": 0.0, "batch_input_shape": [1, 1, 79], "bias_initializer": {"config": {}, "class_name": "Zeros"}, "kernel_regularizer": null, "unroll": false, "recurrent_constraint": null, "name": "simple_rnn_1", "kernel_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}, "implementation": 0, "recurrent_dropout": 0.0, "activation": "relu", "dtype": "float32", "stateful": true, "recurrent_regularizer": null, "bias_constraint": null, "trainable": true, "go_backwards": false, "recurrent_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}}, "class_name": "SimpleRNN"}, {"config": {"return_sequences": false, "use_bias": true, "bias_regularizer": null, "activity_regularizer": null, "kernel_constraint": null, "units": 50, "dropout": 0.0, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "kernel_regularizer": null, "unroll": false, "recurrent_constraint": null, "name": "simple_rnn_2", "kernel_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}, "implementation": 0, "recurrent_dropout": 0.0, "activation": "relu", "stateful": true, "recurrent_regularizer": null, "bias_constraint": null, "trainable": true, "go_backwards": false, "recurrent_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}}, "class_name": "SimpleRNN"}, {"config": {"activity_regularizer": null, "use_bias": true, "bias_regularizer": null, "kernel_constraint": null, "units": 5, "bias_initializer": {"config": {}, "class_name": "Zeros"}, "kernel_regularizer": null, "bias_constraint": null, "trainable": true, "name": "dense_1", "kernel_initializer": {"config": {"minval": -0.05, "maxval": 0.05, "seed": null}, "class_name": "RandomUniform"}, "activation": "softmax"}, "class_name": "Dense"}], "backend": "theano", "class_name": "Sequential"} \ No newline at end of file diff --git a/RNNmodels/full_models/Dataset0.RNN2.cross-rmsprop.88/Dataset0.RNN_2.2C.h5 b/RNNmodels/full_models/Dataset0.RNN2.cross-rmsprop.88/Dataset0.RNN_2.2C.h5 new file mode 100644 index 0000000..263f1c7 Binary files /dev/null and b/RNNmodels/full_models/Dataset0.RNN2.cross-rmsprop.88/Dataset0.RNN_2.2C.h5 differ diff --git a/RNNmodels/full_models/Dataset0.RNN2.cross-rmsprop.88/Dataset0.RNN_2.2C.png b/RNNmodels/full_models/Dataset0.RNN2.cross-rmsprop.88/Dataset0.RNN_2.2C.png new file mode 100644 index 0000000..8b8e7ac Binary files /dev/null and b/RNNmodels/full_models/Dataset0.RNN2.cross-rmsprop.88/Dataset0.RNN_2.2C.png differ diff --git a/RNNmodels/full_models/Dataset0.RNN2.mse-sgd.99/Dataset0.RNN_2C.h5 b/RNNmodels/full_models/Dataset0.RNN2.mse-sgd.99/Dataset0.RNN_2C.h5 new file mode 100644 index 0000000..1aba149 Binary files /dev/null and b/RNNmodels/full_models/Dataset0.RNN2.mse-sgd.99/Dataset0.RNN_2C.h5 differ diff --git a/RNNresults/Dataset0.RNN_1C b/RNNresults/Dataset0.RNN_1C deleted file mode 100644 index ff2b656..0000000 --- a/RNNresults/Dataset0.RNN_1C +++ /dev/null @@ -1,22 +0,0 @@ -RNN_1C Dataset0 Loss:mse Optimizer:sgd Dropout:No -Epoch|Loss|Accuracy|Precision|Recall|Fscore -1|0.0017025100666|0.995273960476|0|0|0 -2|0.00135130978658|0.996309058469|0|0|0 -3|0.00122087410441|0.996567832968|0|0|0 -4|0.00113283317755|0.996799368045|0|0|0 -5|0.00105884889171|0.997085381965|0|0|0 -6|0.00101792979618|0.99724881849|0|0|0 -7|0.000984159224545|0.997316917042|0|0|0 -8|0.000963350689698|0.997371395884|0|0|0 -9|0.000948700413271|0.997357776174|0|0|0 -10|0.000916925185107|0.997507592989|0|0|0 -11|0.000905132005522|0.997493973278|0|0|0 -12|0.000892733087035|0.99754845212|0|0|0 -13|0.000890844276694|0.99754845212|0|0|0 -14|0.000880931287277|0.997534832409|0|0|0 -15|0.000856727237917|0.997616550672|0|0|0 -16|0.000844765846687|0.997684649224|0|0|0 -17|0.000838564708915|0.997671029514|0|0|0 -18|0.00083037975576|0.997671029514|0|0|0 -19|0.000822847591348|0.997739128066|0|0|0 -20|0.000820170220719|0.997766367487|0|0|0 diff --git a/RNNresults/Dataset0.RNN_1C.png b/RNNresults/Dataset0.RNN_1C.png deleted file mode 100644 index a8f4748..0000000 Binary files a/RNNresults/Dataset0.RNN_1C.png and /dev/null differ diff --git a/RNNresults/Dataset0.RNN_2.2C b/RNNresults/Dataset0.RNN_2.2C new file mode 100644 index 0000000..6df4f5f --- /dev/null +++ b/RNNresults/Dataset0.RNN_2.2C @@ -0,0 +1,215 @@ +RNN_2.2C Dataset0 Loss:categorical_crossentropy Optimizer:rmsprop Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|1.41507848758|0.54|0|0|0 +2|1.51834045249|0.54|0|0|0 +3|1.51373778361|0.54|0|0|0 +4|1.48236643364|0.54|0|0|0 +5|1.45524473302|0.54|0|0|0 +6|1.43830270238|0.54|0|0|0 +7|1.42717788788|0.54|0|0|0 +8|1.41834730387|0.54|0|0|0 +9|1.41021490627|0.54|0|0|0 +10|1.40143982756|0.54|0|0|0 +11|1.39011337412|0.54|0|0|0 +12|1.37302453359|0.54|0|0|0 +13|1.34521189357|0.54|0|0|0 +14|1.30203521243|0.54|0|0|0 +15|1.24488273614|0.54|0|0|0 +16|1.18198555822|0.54|0|0|0 +17|1.12137231653|0.54|0|0|0 +18|1.06723350704|0.54|0|0|0 +19|1.02097638028|0.54|0|0|0 +20|0.981239904573|0.54|0|0|0 +21|0.964630887798|0.54|0|0|0 +22|1.08055106971|0.54|0|0|0 +23|1.169145086|0.54|0|0|0 +24|1.33382860729|0.54|0|0|0 +25|1.45026696738|0.54|0|0|0 +26|2.00715190877|0.54|0|0|0 +27|2.08222980965|0.54|0|0|0 +28|2.20014166151|0.54|0|0|0 +29|7.41432431377|0.54|0|0|0 +30|7.41432429737|0.54|0|0|0 +31|7.41432428169|0.54|0|0|0 +32|7.41432426666|0.54|0|0|0 +33|7.41432425229|0.54|0|0|0 +34|7.41432423858|0.54|0|0|0 +35|7.41432422546|0.54|0|0|0 +36|7.41432421288|0.54|0|0|0 +37|7.4143242009|0.54|0|0|0 +38|7.41432418945|0.54|0|0|0 +39|7.41432417842|0.54|0|0|0 +40|7.41432416787|0.54|0|0|0 +41|7.4143241578|0.54|0|0|0 +42|7.41432414826|0.54|0|0|0 +43|7.41432413908|0.54|0|0|0 +44|7.41432413025|0.54|0|0|0 +45|7.41432412191|0.54|0|0|0 +46|7.41432411386|0.54|0|0|0 +47|7.41432410617|0.54|0|0|0 +48|7.4143240989|0.54|0|0|0 +49|7.41432409186|0.54|0|0|0 +50|7.41432408519|0.54|0|0|0 +51|7.41432407875|0.54|0|0|0 +52|7.41432407267|0.54|0|0|0 +53|7.41432406682|0.54|0|0|0 +54|7.41432406122|0.54|0|0|0 +55|7.41432405592|0.54|0|0|0 +56|7.41432405085|0.54|0|0|0 +57|7.41432404596|0.54|0|0|0 +58|7.41432404137|0.54|0|0|0 +59|7.4143240369|0.54|0|0|0 +60|7.41432403273|0.54|0|0|0 +61|7.41432402867|0.54|0|0|0 +62|7.4143240248|0.54|0|0|0 +63|7.41432402116|0.54|0|0|0 +64|7.41432401765|0.54|0|0|0 +65|7.41432401431|0.54|0|0|0 +66|7.41432401115|0.54|0|0|0 +67|7.41432400811|0.54|0|0|0 +68|7.41432400519|0.54|0|0|0 +69|7.41432400245|0.54|0|0|0 +70|7.41432399976|0.54|0|0|0 +71|7.41432399726|0.54|0|0|0 +72|7.41432399488|0.54|0|0|0 +73|7.41432399261|0.54|0|0|0 +74|7.41432399041|0.54|0|0|0 +75|7.41432398832|0.54|0|0|0 +76|7.41432398635|0.54|0|0|0 +77|7.4143239845|0.54|0|0|0 +78|7.41432398272|0.54|0|0|0 +79|7.41432398099|0.54|0|0|0 +80|7.41432397938|0.54|0|0|0 +81|7.41432397783|0.54|0|0|0 +82|7.41432397634|0.54|0|0|0 +83|7.41432397491|0.54|0|0|0 +84|7.4143239736|0.54|0|0|0 +85|7.41432397229|0.54|0|0|0 +86|7.41432397109|0.54|0|0|0 +87|7.41432396996|0.54|0|0|0 +88|7.41432396883|0.54|0|0|0 +89|7.41432396781|0.54|0|0|0 +90|7.4143239668|0.54|0|0|0 +91|7.41432396585|0.54|0|0|0 +92|7.41432396495|0.54|0|0|0 +93|7.41432396406|0.54|0|0|0 +94|7.41432396328|0.54|0|0|0 +95|7.41432396251|0.54|0|0|0 +96|7.41432396173|0.54|0|0|0 +97|7.41432396108|0.54|0|0|0 +98|7.41432396036|0.54|0|0|0 +99|7.41432395977|0.54|0|0|0 +100|7.41432395917|0.54|0|0|0 +RNN_2.2C Dataset0 Loss:categorical_crossentropy Optimizer:rmsprop Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|2.67268687247|0.688648721219|0|0|0 +2|1.93824102401|0.870215479627|0|0|0 +3|1.94238493093|0.873048264751|0|0|0 +4|1.96685093158|0.874202859636|0|0|0 +5|2.04396313844|0.867208162717|0|0|0 +6|2.06498464771|0.862200443042|0|0|0 +7|1.98295646463|0.86967845875|0|0|0 +8|0.127068235395|0.978170101363|0|0|0 +9|0.133022626619|0.986010606162|0|0|0 +10|0.0972860043175|0.990588709136|0|0|0 +11|0.0992587841547|0.990682687789|0|0|0 +12|0.106176113807|0.9911794321|0|0|0 +13|0.113534205089|0.990709538833|0|0|0 +14|0.141972298327|0.98935356112|0|0|0 +15|0.168861743708|0.987863328187|0|0|0 +16|0.168609123531|0.988011008928|0|0|0 +17|0.184526699457|0.986896690609|0|0|0 +18|0.194705262428|0.985836074377|0|0|0 +19|0.184389776195|0.986547627039|0|0|0 +20|0.153752740043|0.98872256159|0|0|0 +21|0.107700103405|0.991192857622|0|0|0 +22|0.094184480247|0.992897898906|0|0|0 +23|0.0886313271141|0.993179834866|0|0|0 +24|0.092601850084|0.993099281735|0|0|0 +25|0.0993740072426|0.992978452037|0|0|0 +26|0.0977530396224|0.993032154125|0|0|0 +27|0.0931257340751|0.993072430691|0|0|0 +28|0.0897778921006|0.99320668591|0|0|0 +RNN_2.2C Dataset0 Loss:categorical_crossentropy Optimizer:rmsprop Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|2.27119484532|0.751039148034|0|0|0 +2|2.16989411396|0.858947540004|0|0|0 +3|2.01651384023|0.869420522155|0|0|0 +4|2.02729002001|0.870167622049|0|0|0 +5|2.03380231453|0.870154038415|0|0|0 +6|2.04451098686|0.869923116629|0|0|0 +7|2.12884851022|0.864992257328|0|0|0 +8|2.2390490002|0.856190062213|0|0|0 +9|2.28304554008|0.855021869651|0|0|0 +10|2.48701345883|0.839998369964|0|0|0 +RNN_2.2C Dataset0 Loss:categorical_crossentropy Optimizer:rmsprop Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|2.82397304243|0.675565024857|0|0|0 +2|2.13108736541|0.850747100026|0|0|0 +3|2.09726760615|0.859868265308|0|0|0 +4|2.10561972278|0.860926598989|0|0|0 +5|2.12568717621|0.861316511398|0|0|0 +6|2.14091720418|0.857487014524|0|0|0 +7|2.24154607893|0.850204007743|0|0|0 +8|2.36255792668|0.839537118269|0|0|0 +9|2.18605110535|0.8551893164|0|0|0 +10|2.23647063786|0.85194468814|0|0|0 +11|2.20177289239|0.855439974377|0|0|0 +12|2.14299434316|0.862430546852|0|0|0 +13|2.12894257559|0.86443581067|0|0|0 +14|2.11065586731|0.865535920681|0|0|0 +15|2.10388162471|0.865939758533|0|0|0 +16|2.09613211982|0.866482850817|0|0|0 +17|2.0894859017|0.867527259055|0|0|0 +18|2.088436631|0.867666513487|0|0|0 +19|2.09507632099|0.867555109941|0|0|0 +20|2.10545054979|0.866552478033|0|0|0 +RNN_2.2C Dataset0 Loss:categorical_crossentropy Optimizer:rmsprop Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|7.43847173756|0.538150615956|0|0|0 +2|7.4384805985|0.538150615956|0|0|0 +3|7.43849348543|0.538150615956|0|0|0 +4|7.43851200751|0.538150615956|0|0|0 +5|7.43854054597|0.538150615956|0|0|0 +6|7.43859453767|0.538150615956|0|0|0 +7|7.43876544518|0.538150615956|0|0|0 +8|7.44413820731|0.538150615956|0|0|0 +9|7.44413767406|0.538150615956|0|0|0 +10|7.44413725215|0.538150615956|0|0|0 +11|7.44413689404|0.538150615956|0|0|0 +12|7.4441365741|0.538150615956|0|0|0 +13|7.44413627957|0.538150615956|0|0|0 +14|7.44413600439|0.538150615956|0|0|0 +15|7.44413574555|0.538150615956|0|0|0 +16|7.44413550137|0.538150615956|0|0|0 +17|7.44413527076|0.538150615956|0|0|0 +18|7.44413505294|0.538150615956|0|0|0 +19|7.44413484732|0.538150615956|0|0|0 +20|7.44413465343|0.538150615956|0|0|0 +RNN_2.2C Dataset0 Loss:categorical_crossentropy Optimizer:rmsprop Dropout:No +Epoch|Loss|Accuracy|Precision|Recall|Fscore +1|2.10137824094|0.747518146883|0|0|0 +2|2.25788667355|0.754496690863|0|0|0 +3|2.16028782609|0.746210503843|0|0|0 +4|1.8849821173|0.87078351836|0|0|0 +5|1.92663679914|0.8735455807|0|0|0 +6|2.05941114769|0.86686058924|0|0|0 +7|2.13815123397|0.864018467122|0|0|0 +8|2.15313395554|0.862670794193|0|0|0 +9|2.19893831588|0.858414282664|0|0|0 +10|2.57668394945|0.831380764304|0|0|0 +11|2.05958188201|0.863778287788|0|0|0 +12|1.90354238678|0.87369235696|0|0|0 +13|1.86199024802|0.881791737831|0|0|0 +14|1.86699041035|0.88128469257|0|0|0 +15|1.86759327804|0.880871050384|0|0|0 +16|1.85687929758|0.882578992314|0|0|0 +17|1.85266491189|0.882925918019|0|0|0 +18|1.8534419431|0.883046007686|0|0|0 +19|1.85133446853|0.883726515798|0|0|0 +20|1.8533526238|0.883513023057|0|0|0 +21|1.85642832513|0.883179440649|0|0|0 +22|1.86329664731|0.882712425278|0|0|0 +23|1.86771824858|0.882298783091|0|0|0 +24|1.87593801835|0.881524871904|0|0|0 +25|1.88133283514|0.88103116994|0|0|0 diff --git a/python3 b/python3 new file mode 100644 index 0000000..e69de29 diff --git a/reader.py b/reader.py index 4315214..e264783 100644 --- a/reader.py +++ b/reader.py @@ -178,7 +178,7 @@ def getDataset(DataSetType): fp_att.readline() #read away the first line (title) #Train Dataset: 10 legitimate and 10 attack samples, loop 30,000 times. #TOT 300,000 leg, 300,000 att. - for i in range(1000): ############ CORRECTION: TOTAL 10,000 legitimate, 10,000 attack + for i in range(3000): ############ CORRECTION: TOTAL 30,000 legitimate, 30,000 attack for j in range(10): Reader.write_it(x_train, y_train, fp_leg, 0) for j in range(10):