-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_results.py
153 lines (126 loc) · 4.78 KB
/
plot_results.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import os
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
sns.set_theme(style="whitegrid", palette="colorblind")
for result_type in ["numerical", "categorical", "uci"]:
result_filename = f"out/benchmark_results_{result_type}.csv"
if not os.path.isfile(result_filename):
continue
print(result_type)
results_df = pd.read_csv(result_filename)
hue_order = [
"diffprivlib tree",
"DPGDT",
"BDPT",
"private tree",
"private tree (non-priv. quantiles)",
]
for epsilon in [0.01, 0.1, 1.0]:
print(epsilon)
eps_results = results_df[
(results_df["epsilon"] == epsilon) | (results_df["epsilon"].isna())
]
epsilon_text = str(epsilon).replace(".", "_")
sns.barplot(
data=eps_results,
x="dataset",
y="test accuracy",
hue="method",
hue_order=hue_order,
)
plt.tight_layout()
plt.savefig(f"out/test_accuracy_datasets_{result_type}_{epsilon_text}.png")
plt.savefig(f"out/test_accuracy_datasets_{result_type}_{epsilon_text}.pdf")
plt.close()
# This reorders the columns and removes the 'dummy' column
column_order = [
"dataset",
"regular tree",
"BDPT",
"private tree (non-priv. quantiles)",
"DPGDT",
"diffprivlib tree",
"private tree",
]
if result_type == "numerical":
eps_results.loc[eps_results["method"] == "DPGDT", "test accuracy"] = -1
eps_results.loc[eps_results["method"] == "DPGDT", "runtime"] = -1
mean_table = pd.pivot_table(
eps_results,
index="dataset",
columns="method",
values="test accuracy",
aggfunc="mean",
).reset_index()
mean_table = mean_table[column_order]
sem_table = pd.pivot_table(
eps_results,
index="dataset",
columns="method",
values="test accuracy",
aggfunc="sem",
).reset_index()
sem_table = sem_table[column_order]
def concat_and_format(mean, sem):
if isinstance(mean, str):
return mean
return f"{mean:.3f} \\tiny $\\pm$ {sem:.3f}"
concat_and_format_vec = np.vectorize(concat_and_format)
formatted_scores = pd.DataFrame(
concat_and_format_vec(mean_table, sem_table), columns=column_order
)
method_mapping = {
"regular tree": "decision tree",
"diffprivlib tree": "diffprivlib",
"private tree": "PrivaTree",
"private tree (non-priv. quantiles)": "PrivaTree leaking splits",
}
formatted_scores = formatted_scores.rename(columns=method_mapping)
formatted_scores["dataset"] = formatted_scores["dataset"].apply(
lambda x: x.replace("_", "\\_")
)
print(formatted_scores.to_csv(index=False))
if epsilon == 0.1:
print("runtime data:")
mean_runtime_table = pd.pivot_table(
eps_results,
index="dataset",
columns="method",
values="runtime",
aggfunc="mean",
).reset_index()
mean_runtime_table = mean_runtime_table[column_order]
sem_runtime_table = pd.pivot_table(
eps_results,
index="dataset",
columns="method",
values="runtime",
aggfunc="sem",
).reset_index()
sem_runtime_table = sem_runtime_table[column_order]
def concat_and_format(mean, sem):
if isinstance(mean, str):
return mean
if np.isnan(mean):
return "-"
if round(mean) == 0:
return f"<1 \\tiny $\\pm$ {sem:.0f}"
return f"{mean:.0f} \\tiny $\\pm$ {sem:.0f}"
concat_and_format_vec = np.vectorize(concat_and_format)
formatted_scores = pd.DataFrame(
concat_and_format_vec(mean_runtime_table, sem_runtime_table),
columns=column_order,
)
method_mapping = {
"regular tree": "decision tree",
"diffprivlib tree": "diffprivlib",
"private tree": "PrivaTree",
"private tree (non-priv. quantiles)": "PrivaTree leaking splits",
}
formatted_scores = formatted_scores.rename(columns=method_mapping)
formatted_scores["dataset"] = formatted_scores["dataset"].apply(
lambda x: x.replace("_", "\\_")
)
print(formatted_scores.to_csv(index=False))