-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathboxplot.py
More file actions
109 lines (92 loc) · 2.71 KB
/
Copy pathboxplot.py
File metadata and controls
109 lines (92 loc) · 2.71 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import numpy as np
import matplotlib.pyplot as plt
def boxplot(
X, tick_labels: list[str], colors: list[tuple], x_label: str, result_path: str
):
plt.rcParams["font.size"] = 32
_, ax = plt.subplots(figsize=(10, 8))
X = np.flip(X).tolist()
tick_labels = np.flip(tick_labels).tolist()
bplot = ax.boxplot(
X,
tick_labels=tick_labels,
showfliers=False,
patch_artist=True,
showmeans=True,
# meanline=True,
orientation="horizontal",
)
for median in bplot["medians"]:
median.set_color("black")
for mean in bplot["means"]:
mean.set_color("red")
for patch, color in zip(bplot["boxes"], colors):
patch.set_facecolor(color)
ax.set_xlabel(x_label.upper())
ax.set_xlim(-0.05, 1.05)
plt.tight_layout()
plt.savefig(result_path)
plt.clf()
plt.close()
result_dir = os.path.join(os.getcwd(), "result")
datasets = ["SMD", "SMAP"]
metrics = ["auc_roc", "auc_pr", "vus_pr", "pate"]
tick_labels = [
"TranAD",
"LSTM-AE",
"FedAvg TranAD",
"FedAvg LSTM-AE",
"IncFed ESN-SRE",
"FedAvg MD-RS",
"IncFed MD-RS",
]
colors = [
(216 / 255, 85 / 255, 255 / 255, 1 - i / len(tick_labels))
for i in range(len(tick_labels))
]
for dataset in datasets:
for metric in metrics:
result_path = os.path.join(result_dir, f"{dataset}-{metric}.pdf")
X = [
np.genfromtxt(
os.path.join(
os.getcwd(), f"result/tranad/centralized/{dataset}/{metric}.csv"
)
),
np.genfromtxt(
os.path.join(
os.getcwd(), f"result/lstmae/centralized/{dataset}/{metric}.csv"
)
),
np.genfromtxt(
os.path.join(
os.getcwd(), f"result/tranad/fedavg/{dataset}/{metric}.csv"
)
),
np.genfromtxt(
os.path.join(
os.getcwd(), f"result/lstmae/fedavg/{dataset}/{metric}.csv"
)
),
np.genfromtxt(
os.path.join(
os.getcwd(), f"result/ESN-SRE/IncFed/{dataset}/{metric}.csv"
)
),
np.genfromtxt(
os.path.join(os.getcwd(), f"result/mdrs/fedavg/{dataset}/{metric}.csv")
),
np.genfromtxt(
os.path.join(
os.getcwd(), f"result/mdrs/proposed/{dataset}/{metric}.csv"
)
),
]
boxplot(
X,
tick_labels=tick_labels,
colors=colors,
x_label=metric,
result_path=result_path,
)