Commit bb0354f0 by Stalin Munoz

new parameters to main method

parent 05b4ddf8
import cnn from cnn import CNN_Antifrag
from parser import parse_data from parser import parse_data
import itertools import itertools
from confusion_matrix import plot_confusion_matrix from confusion_matrix import plot_confusion_matrix
""" """
(c,b,e) will be read from the command line or a script (c,b,e,o) will be read from the command line or a script
(c,b,e) corresponds to the combinations of the specific hyperparameters to build the model (c,b,e,o) corresponds to the combinations of the specific hyperparameters
to build the model
c belongs to {0,1,2,3} and represents the layer architecture c belongs to {0,1,2,3} and represents the layer architecture
b belongs to {0,1} and represents the batch size b belongs to {0,1} and represents the batch size
e belongs to {0,1} and represents the number of epochs e belongs to {0,1} and represents the number of epochs
o belongs to {0,1,2} and represents the balancing method
""" """
#reading arguments from command line
#c = int(sys.argv[1])
#b = int(sys.argv[2])
#e = int(sys.argv[3])
c_ = [0,1,2,3] c_ = [0,1,2,3]
b_ = [0,1] b_ = [1]
e_ = [0,1] e_ = [0]
n_experiences = 10001 o_ = [0,1,2]
combinations = itertools.product(c_,b_,e_)
n_experiences = 100
combinations = itertools.product(c_,b_,e_,o_)
#parse the data
input_, output_ = parse_data(n_experiences)
#run an specific combination #parse the data
max_params = (0,0,0) input_, output_ = parse_data(n_experiences,kind='linear')
#%%
max_avg_auc = 0 max_avg_auc = 0
for params in combinations: for params in combinations:
avg_acc, avg_auc, X_train_kfold, X_test_kfold, y_train_kfold, y_test_kfold = cnn.run_nn(input_, output_, n_experiences, params) cnn = CNN_Antifrag(name="CNN_%d_%d_%d_%d"%params)
avg_acc, avg_auc = cnn.run_nn(input_, output_, params)
if avg_auc > max_avg_auc: if avg_auc > max_avg_auc:
max_avg_auc = avg_auc max_avg_auc = avg_auc
max_params = params max_params = params
X_train_kfold_opt = X_train_kfold
X_test_kfold_opt = X_test_kfold
y_train_kfold_opt = y_train_kfold
y_test_kfold_opt = y_test_kfold
#%%
print("Best params:",max_params)
# once we have chosen the optimal parameters we can do the normal kfold # once we have chosen the optimal parameters we can do the normal kfold
cnn = CNN_Antifrag(name="CNN_%d_%d_%d_%d"%max_params)
#note: the test data remains unbalanced acc, auc, cm, pr = cnn.run_kfold(input_, output_, max_params)
acc, auc, cm, pr = cnn.run_kfold(X_train_kfold_opt, X_test_kfold_opt, y_train_kfold_opt, y_test_kfold_opt, max_params)
#to add: precision recall curve #to add: precision recall curve
#%%
labels = ['~robust&~evolvable', 'evolvable&~robust', 'robust&~evolvable', 'robust&evolvable'] labels = [
plot_confusion_matrix(cm, labels) #this function saves the matrix image automatically '[~R & ~E]',
'[~R & E]',
f = open("acc_auc.txt", 'w+') '[ R & ~E]',
'[ R & E]'
]
#this function saves the matrix image automatically
plot_confusion_matrix(cm, labels)
f = open("out/acc_auc.txt", 'w+')
f.write("Average accuracy: " + str(acc)+"\n") f.write("Average accuracy: " + str(acc)+"\n")
f.write("Average area under the curve: " + str(auc)) f.write("Average area under the curve: " + str(auc))
f.close() f.close()
## TO DO: code that allows to execute in parallel, make sure it's the same random shuffle ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment