Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Troubled Cell Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Laura Christine Kühle
Troubled Cell Detection
Commits
bab035e0
Commit
bab035e0
authored
3 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Added f-score and AUROC to classification evaluation.
parent
0e2f343d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ANN_Training.py
+20
-7
20 additions, 7 deletions
ANN_Training.py
Plotting.py
+6
-1
6 additions, 1 deletion
Plotting.py
with
26 additions
and
8 deletions
ANN_Training.py
+
20
−
7
View file @
bab035e0
...
...
@@ -8,6 +8,9 @@ TODO: Add log to pipeline
TODO: Remove object set-up
TODO: Optimize Snakefile-vs-config relation
TODO: Improve maximum selection runtime
TODO: Discuss if we want training accuracy/ROC in addition to CFV
TODO: Discuss whether to change output to binary
TODO: Adapt TCD file to new classification
"""
import
numpy
as
np
...
...
@@ -17,7 +20,7 @@ import torch
from
torch.utils.data
import
TensorDataset
,
DataLoader
,
random_split
from
sklearn.model_selection
import
KFold
# from sklearn.metrics import accuracy_score
from
sklearn.metrics
import
accuracy_score
,
precision_recall_fscore_support
,
precision_score
from
sklearn.metrics
import
accuracy_score
,
precision_recall_fscore_support
,
precision_score
,
roc_auc_score
,
roc_curve
import
ANN_Model
from
Plotting
import
plot_classification_accuracy
...
...
@@ -142,18 +145,28 @@ class ModelTrainer(object):
x_test
,
y_test
=
test_set
# print(self._model(x_test.float()))
model_score
=
self
.
_model
(
x_test
.
float
())
model_output
=
torch
.
tensor
([[
1.0
,
0.0
]
if
value
==
0
else
[
0.0
,
1.0
]
for
value
in
torch
.
max
(
self
.
_model
(
x_test
.
float
())
,
1
)[
1
]])
for
value
in
torch
.
max
(
model_score
,
1
)[
1
]])
y_true
=
y_test
.
detach
().
numpy
()
y_pred
=
model_output
.
detach
().
numpy
()
y_true
=
y_test
.
detach
().
numpy
()[:,
0
]
y_pred
=
model_output
.
detach
().
numpy
()[:,
0
]
# y_score = model_score.detach().numpy()[:, 0]
accuracy
=
accuracy_score
(
y_true
,
y_pred
)
# print('sklearn', accuracy)
precision
,
recall
,
f_score
,
support
=
precision_recall_fscore_support
(
y_true
,
y_pred
)
# print(precision, recall)
# print(precision, recall
, f_score
)
# print()
return
[
precision
[
0
],
recall
[
0
],
accuracy
]
# auroc = roc_auc_score(y_true, y_score)
# print('auroc raw', auroc)
auroc
=
roc_auc_score
(
y_true
,
y_pred
)
print
(
'
auroc true
'
,
auroc
)
# fpr, tpr, thresholds = roc_curve(y_true, y_score)
# roc = [tpr, fpr, thresholds]
# print(roc)
# plt.plot(fpr, tpr, label="AUC="+str(auroc))
return
[
precision
[
0
],
recall
[
0
],
accuracy
,
f_score
[
0
],
auroc
]
def
save_model
(
self
):
# Saving Model
...
...
This diff is collapsed.
Click to expand it.
Plotting.py
+
6
−
1
View file @
bab035e0
...
...
@@ -3,6 +3,7 @@
@author: Laura C. Kühle
TODO: Give option to select plotting color
TODO: Improve classification plotting
"""
import
numpy
as
np
...
...
@@ -235,7 +236,7 @@ def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_le
return
grid
,
exact
def
plot_classification_accuracy
(
xlabels
,
precision
,
recall
,
accuracy
):
def
plot_classification_accuracy
(
xlabels
,
precision
,
recall
,
accuracy
,
fscore
,
auroc
):
"""
Plots classification accuracy.
Plots the accuracy, precision, and recall in a bar plot.
...
...
@@ -255,13 +256,17 @@ def plot_classification_accuracy(xlabels, precision, recall, accuracy):
precision
=
[
precision
]
recall
=
[
recall
]
accuracy
=
[
accuracy
]
fscore
=
[
fscore
]
auroc
=
[
auroc
]
pos
=
np
.
arange
(
len
(
xlabels
))
width
=
0.3
fig
=
plt
.
figure
(
'
classification_accuracy
'
)
ax
=
fig
.
add_axes
([
0.15
,
0.1
,
0.75
,
0.8
])
ax
.
bar
(
pos
-
2
*
width
,
fscore
,
width
,
label
=
'
F-Score
'
)
ax
.
bar
(
pos
-
width
,
precision
,
width
,
label
=
'
Precision
'
)
ax
.
bar
(
pos
,
recall
,
width
,
label
=
'
Recall
'
)
ax
.
bar
(
pos
+
width
,
accuracy
,
width
,
label
=
'
Accuracy
'
)
ax
.
bar
(
pos
+
2
*
width
,
auroc
,
width
,
label
=
'
AUROC
'
)
ax
.
set_xticks
(
pos
)
ax
.
set_xticklabels
(
xlabels
)
ax
.
set_ylabel
(
'
Classification (%)
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment