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
34062b83
Commit
34062b83
authored
Dec 08, 2019
by
Pamela Osuna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final kfold added
parent
5945ed43
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
cnn.py
+58
-0
No files found.
cnn.py
View file @
34062b83
...
...
@@ -124,4 +124,62 @@ def run_nn(input_, output_, n_experiences, params):
print
(
"Average accuracy: "
,
total_acc
)
print
(
"Average area under the curve: "
,
total_auc
)
return
total_acc
,
total_auc
,
X_train_kfold
,
X_test_kfold
,
validation_Y_one_hot
def
run_kfold
(
X_train
,
X_test
,
y_train
,
y_test
,
params
):
c
,
b
,
e
=
params
for
i
in
range
(
N_SPLITS
):
# change the labels from categorical to one-hot encoding
y_train
[
i
]
=
to_categorical
(
y_train
[
i
],
num_classes
=
4
)
y_test
[
i
]
=
to_categorical
(
y_test
[
i
],
num_classes
=
4
)
#convert input to np.array
X_train
[
i
]
=
np
.
array
(
X_train
[
i
])
X_test
[
i
]
=
np
.
array
(
X_test
[
i
])
#convert each element of the train and test set into a matrix of size 30x1(?)
X_train
[
i
]
=
X_train
[
i
]
.
reshape
(
-
1
,
30
,
1
)
X_test
[
i
]
=
X_test
[
i
]
.
reshape
(
-
1
,
30
,
1
)
#convert the data from an int8 format to a float32 type
X_train
[
i
]
=
X_train
[
i
]
.
astype
(
'float32'
)
X_test
[
i
]
=
X_test
[
i
]
.
astype
(
'float32'
)
# defining keras model
model
=
m
.
model_architecture
(
c
)
#compile the keras model
model
.
compile
(
loss
=
'categorical_crossentropy'
,
optimizer
=
'adam'
,
metrics
=
[
'accuracy'
])
total_acc
=
0
total_auc
=
0
bs
,
ep
=
m
.
choose_batch_epochs
(
b
,
e
)
for
i
in
range
(
N_SPLITS
):
#train the model
model
.
fit
(
X_train
[
i
],
y_train
[
i
],
batch_size
=
bs
,
epochs
=
ep
,
verbose
=
1
,
validation_data
=
(
X_test
[
i
],
y_test
[
i
]))
#calculate accuracy
_
,
accuracy
=
model
.
evaluate
(
X_test
[
i
],
y_test
[
i
],
verbose
=
0
)
total_acc
+=
accuracy
print
(
"t_set = "
+
str
(
i
))
print
(
'Test accuracy:'
,
accuracy
)
# calculate area under the curve
y_pred
=
model
.
predict
(
X_validation
,
batch_size
=
bs
)
fpr
,
tpr
,
auc
=
ra
.
roc_auc
(
N_CLASSES
,
validation_Y_one_hot
,
y_pred
)
total_auc
+=
auc
print
(
"Area under the curve:"
,
auc
)
total_acc
=
total_acc
/
(
N_SPLITS
)
total_auc
=
total_acc
/
(
N_SPLITS
)
print
(
"Average accuracy: "
,
total_acc
)
print
(
"Average area under the curve: "
,
total_auc
)
return
total_acc
,
total_auc
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