-
Notifications
You must be signed in to change notification settings - Fork 100
/
visualize.py
74 lines (68 loc) · 2.13 KB
/
visualize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import numpy as np
from matplotlib import pyplot as plt
def plot_roc(fpr_list, tpr_list, roc_auc, path):
"""Function to get the ROC plot using FPR and TPR results
Args:
fpr_list (list or ndarray): List of FPR values
tpr_list (list or ndarray): List of TPR values
roc_auc (float or floating): Area Under the ROC Curve
path (str): Folder for saving the ROC plot
"""
range01 = np.linspace(0, 1)
plt.fill_between(fpr_list, tpr_list, alpha=0.15)
plt.plot(fpr_list, tpr_list, label="ROC curve")
plt.plot(range01, range01, "--", label="Random guess")
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.grid()
plt.legend()
plt.xlabel("False positive rate (FPR)")
plt.ylabel("True positive rate (TPR)")
plt.title("ROC curve")
plt.text(
0.7,
0.3,
f"AUC = {roc_auc:.03f}",
horizontalalignment="center",
verticalalignment="center",
bbox=dict(facecolor="white", alpha=0.5),
)
plt.savefig(
fname=path,
dpi=1000,
)
plt.clf()
def plot_roc_log(fpr_list, tpr_list, roc_auc, path):
"""Function to get the log-scale ROC plot using FPR and TPR results
Args:
fpr_list (list or ndarray): List of False Positive Rate values
tpr_list (list or ndarray): List of True Positive Rate values
roc_auc (float or floating): Area Under the ROC Curve
path (str): Folder for saving the ROC plot
"""
range01 = np.linspace(0, 1)
plt.fill_between(fpr_list, tpr_list, alpha=0.15)
plt.plot(fpr_list, tpr_list, label="ROC curve")
plt.plot(range01, range01, "--", label="Random guess")
plt.xlim([10e-6, 1])
plt.ylim([10e-6, 1])
plt.xscale("log")
plt.yscale("log")
plt.grid()
plt.legend()
plt.xlabel("False positive rate (FPR)")
plt.ylabel("True positive rate (TPR)")
plt.title("ROC curve")
plt.text(
0.7,
0.3,
f"AUC = {roc_auc:.03f}",
horizontalalignment="center",
verticalalignment="center",
bbox=dict(facecolor="white", alpha=0.5),
)
plt.savefig(
fname=path,
dpi=1000,
)
plt.clf()