Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
antifragility
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ana Pamela Osuna Vargas
antifragility
Commits
bb0354f0
Commit
bb0354f0
authored
Jan 19, 2020
by
Stalin Munoz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new parameters to main method
parent
05b4ddf8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
30 deletions
+30
-30
main.py
+30
-30
No files found.
main.py
View file @
bb0354f0
import
cnn
from
cnn
import
CNN_Antifrag
from
parser
import
parse_data
import
itertools
from
confusion_matrix
import
plot_confusion_matrix
"""
(c,b,e) 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) will be read from the command line or a script
(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
b belongs to {0,1} and represents the batch size
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
]
b_
=
[
0
,
1
]
e_
=
[
0
,
1
]
n_experiences
=
10001
combinations
=
itertools
.
product
(
c_
,
b_
,
e_
)
b_
=
[
1
]
e_
=
[
0
]
o_
=
[
0
,
1
,
2
]
n_experiences
=
100
combinations
=
itertools
.
product
(
c_
,
b_
,
e_
,
o_
)
#parse the data
input_
,
output_
=
parse_data
(
n_experiences
)
#run an specific combination
max_params
=
(
0
,
0
,
0
)
#parse the data
input_
,
output_
=
parse_data
(
n_experiences
,
kind
=
'linear'
)
#%%
max_avg_auc
=
0
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
:
max_avg_auc
=
avg_auc
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
#note: the test data remains unbalanced
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
)
cnn
=
CNN_Antifrag
(
name
=
"CNN_
%
d_
%
d_
%
d_
%
d"
%
max_params
)
acc
,
auc
,
cm
,
pr
=
cnn
.
run_kfold
(
input_
,
output_
,
max_params
)
#to add: precision recall curve
labels
=
[
'~robust&~evolvable'
,
'evolvable&~robust'
,
'robust&~evolvable'
,
'robust&evolvable'
]
plot_confusion_matrix
(
cm
,
labels
)
#this function saves the matrix image automatically
f
=
open
(
"acc_auc.txt"
,
'w+'
)
#%%
labels
=
[
'[~R & ~E]'
,
'[~R & E]'
,
'[ 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 area under the curve: "
+
str
(
auc
))
f
.
close
()
## TO DO: code that allows to execute in parallel, make sure it's the same random shuffle ...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment