Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Liu Qianqiao
Text_Analysis
Commits
a82feab7
Commit
a82feab7
authored
Feb 19, 2020
by
Liu Qianqiao
Browse files
Upload New File
parent
a16e5a72
Changes
1
Hide whitespace changes
Inline
Side-by-side
classification_modules/nn_utils.py
0 → 100644
View file @
a82feab7
from
keras.callbacks
import
Callback
,
EarlyStopping
,
ModelCheckpoint
class
TrainingHistory
(
Callback
):
def
__init__
(
self
,
x_test
,
y_test
,
CLASSES_LIST
):
super
(
Callback
,
self
).
__init__
()
self
.
x_test
=
x_test
self
.
y_test
=
y_test
self
.
CLASSES_LIST
=
CLASSES_LIST
def
on_train_begin
(
self
,
logs
=
{}):
self
.
losses
=
[]
self
.
epoch_losses
=
[]
self
.
epoch_val_losses
=
[]
self
.
val_losses
=
[]
self
.
predictions
=
[]
self
.
epochs
=
[]
self
.
f1
=
[]
self
.
i
=
0
self
.
save_every
=
50
def
on_epoch_end
(
self
,
epoch
,
logs
=
{}):
y_predicted
=
self
.
model
.
predict
(
self
.
x_test
).
argmax
(
1
)
print
(
y_predicted
.
shape
)
print
(
"Test Accuracy:"
,
accuracy_score
(
self
.
y_test
,
y_predicted
))
p
,
r
,
f1
,
s
=
precision_recall_fscore_support
(
self
.
y_test
,
y_predicted
,
average
=
'micro'
,
labels
=
[
x
for
x
in
self
.
CLASSES_LIST
])
print
(
'p r f1 %.1f %.1f %.1f'
%
(
np
.
average
(
p
,
weights
=
s
)
*
100.0
,
np
.
average
(
r
,
weights
=
s
)
*
100.0
,
np
.
average
(
f1
,
weights
=
s
)
*
100.0
))
try
:
print
(
classification_report
(
self
.
y_test
,
y_predicted
,
labels
=
[
x
for
x
in
self
.
CLASSES_LIST
]))
except
:
print
(
'ZERO'
)
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