-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_scatter_boxplot_heatmap_radar_line.py
More file actions
200 lines (170 loc) · 7.8 KB
/
Copy pathplot_scatter_boxplot_heatmap_radar_line.py
File metadata and controls
200 lines (170 loc) · 7.8 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Dataset names in order
datasets = ["MUTAG", "PTC-MR", "PROTEINS", "NCI1", "Mutagenicity"]
# Raw accuracy data from the LaTeX table (mean and std separated)
raw_data = {
"CGCN (2L)": [(71.2, 2.1), (59.7, 4.2), (70.9, 2.4), (62.3, 1.1), (61.9, 2.7)],
"GCN (2L)": [(55.0, 22.0), (48.5, 10.4), (59.5, 4.1), (50.8, 1.7), (54.7, 1.1)],
"GCN (6L)": [(61.2, 21.6), (55.0, 15.8), (58.7, 6.1), (50.8, 1.7), (54.7, 1.9)],
"CGIN (2L)": [(83.2, 7.3), (63.2, 4.7), (70.1, 2.6), (63.6, 2.3), (59.1, 1.8)],
"GIN (2L)": [(60.0, 17.6), (45.0, 9.5), (50.4, 12.0), (55.5, 1.4), (54.8, 2.0)],
"GIN (6L)": [(61.2, 1.6), (48.5, 13.4), (61.6, 1.2), (60.8, 2.8), (55.8, 2.0)],
"CGAT (2L)": [(72.5, 4.7), (59.7, 6.0), (71.8, 2.5), (64.6, 0.0), (58.8, 3.6)],
"GAT (2L)": [(65.0, 9.3), (51.4, 15.7), (60.0, 3.3), (51.9, 2.2), (54.8, 2.0)],
"GAT (6L)": [(68.7, 4.1), (54.2, 17.2), (63.1, 1.8), (52.3, 2.9), (54.8, 2.0)],
"CGATv2 (2L)": [(68.7, 4.1), (59.0, 5.2), (71.3, 0.6), (63.6, 1.1), (62.3, 4.2)],
"GATv2 (2L)": [(55.0, 19.0), (49.2, 15.3), (61.6, 1.6), (49.5, 2.0), (55.9, 1.4)],
"GATv2 (6L)": [(57.5, 16.0), (49.2, 15.3), (63.3, 2.1), (49.5, 2.0), (59.6, 6.2)],
"CResGatedGCN (2L)": [(68.7, 4.1), (60.4, 5.8), (72.5, 1.0), (62.4, 3.2), (59.6, 3.7)],
"ResGatedGCN (2L)": [(57.0, 16.7), (50.7, 17.7), (47.9, 9.9), (56.8, 6.6), (56.1, 2.1)],
"ResGatedGCN (6L)": [(65.0, 15.8), (50.7, 7.1), (55.8, 8.7), (61.1, 3.1), (56.1, 2.1)],
"CGraphSAGE (2L)": [(68.7, 4.1), (65.3, 11.5), (73.8, 3.7), (63.7, 1.0), (66.3, 5.3)],
"GraphSAGE (2L)": [(57.4, 16.0), (52.8, 7.4), (62.5, 0.8), (53.1, 6.0), (58.1, 3.6)],
"GraphSAGE (6L)": [(51.2, 1.9), (55.7, 12.5), (63.1, 1.8), (53.2, 6.1), (60.0, 3.3)],
"CGraphTrans (2L)": [(68.7, 4.1), (63.3, 10.8), (70.7, 3.1), (63.1, 2.8), (63.2, 4.7)],
"GraphTrans (2L)": [(57.4, 16.0), (40.4, 8.0), (60.7, 2.6), (55.0, 3.7), (53.6, 1.3)],
"GraphTrans (6L)": [(67.5, 7.4), (49.2, 12.3), (61.6, 1.2), (61.5, 2.5), (59.9, 4.6)],
"CGraphGPS (2L)": [(83.7, 2.1), (65.5, 9.3), (81.6, 7.2), (60.1, 6.1), (59.4, 4.1)],
"GraphGPS (2L)": [(50.9, 19.6), (49.2, 20.1), (38.0, 1.9), (50.8, 2.6), (41.4, 8.7)],
"GraphGPS (6L)": [(52.5, 2.1), (46.4, 2.3), (38.8, 1.5), (49.4, 1.9), (55.1, 5.5)],
}
# Create a MultiIndex DataFrame
index = list(raw_data.keys())
columns = pd.MultiIndex.from_product([datasets, ['mean', 'std']])
data = []
for model_scores in raw_data.values():
row = []
for score in model_scores:
row.extend(score)
data.append(row)
df = pd.DataFrame(data, index=index, columns=columns)
df.to_csv("graph_model_results.csv")
# Helper to safely get a value from the dataframe
def safe_get(model_name, dataset):
try:
return df.loc[model_name, (dataset, 'mean')]
except (KeyError, IndexError):
return float('-inf')
# Extract convex models
convex_models = [m for m in df.index if m.startswith("C")]
# === Boxplot of improvements ===
improvements = []
for model in convex_models:
base = model[1:].split(' ')[0] # Remove 'C'
for ds in datasets:
try:
convex_score = df.loc[model, (ds, 'mean')]
except (KeyError, IndexError):
continue
base_2L = f"{base} (2L)"
base_6L = f"{base} (6L)"
best_nonconvex = max(safe_get(base_2L, ds), safe_get(base_6L, ds))
if best_nonconvex > 0:
diff = convex_score - best_nonconvex
improvements.append({'Model': model, 'Dataset': ds, 'Improvement': diff})
improvements_df = pd.DataFrame(improvements)
if not improvements_df.empty:
plt.figure(figsize=(8, 6))
sns.boxplot(data=improvements_df, x="Dataset", y="Improvement", color='skyblue')
sns.stripplot(data=improvements_df, x="Dataset", y="Improvement", color='black', size=4, jitter=True)
plt.axhline(0, color='gray', linestyle='--')
plt.title("Distribution of Convex Model Improvements Across Datasets")
plt.tight_layout()
plt.savefig("boxplot_improvements.png")
plt.close()
else:
print("Warning: No improvement data available for boxplot.")
# === Scatter Plot: Convex vs. Non-Convex ===
conv_scores = []
nonconv_scores = []
for model in convex_models:
base = model[1:].split(' ')[0] # Remove 'C'
for ds in datasets:
try:
convex_score = df.loc[model, (ds, 'mean')]
except (KeyError, IndexError):
continue
base_2L = f"{base} (2L)"
base_6L = f"{base} (6L)"
best_nonconvex = max(safe_get(base_2L, ds), safe_get(base_6L, ds))
if best_nonconvex > 0:
conv_scores.append(convex_score)
nonconv_scores.append(best_nonconvex)
if conv_scores and nonconv_scores:
plt.figure(figsize=(6, 6))
plt.scatter(nonconv_scores, conv_scores, alpha=0.7)
min_val = min(min(conv_scores), min(nonconv_scores), 40)
max_val = max(max(conv_scores), max(nonconv_scores), 90)
plt.plot([min_val, max_val], [min_val, max_val], '--', color='gray')
plt.xlabel("Best Non-Convex Accuracy (%)")
plt.ylabel("Convex Accuracy (%)")
plt.title("Convex vs. Best Non-Convex Accuracy")
plt.grid(True)
plt.tight_layout()
plt.savefig("scatter_convex_vs_nonconvex.png")
plt.close()
else:
print("Warning: No data available for scatter plot.")
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
# Sample: Load your processed DataFrame (based on the table you gave)
# Each row is a model, each column is a dataset
# The DataFrame should already contain mean and std values as two-level columns
# For example: df.loc['CGCN (2L)', ('MUTAG', 'mean')] = 71.2
# Example placeholder for structure – replace with actual data extraction
# df = ...
datasets = ['MUTAG', 'PTC-MR', 'PROTEINS', 'NCI1', 'Mutagenicity']
convex_models = [idx for idx in df.index]
# --- 1. Line plots: performance trends per model across datasets ---
plt.figure(figsize=(10, 6))
for model in convex_models:
means = [df.loc[model, (ds, 'mean')] for ds in datasets]
stds = [df.loc[model, (ds, 'std')] for ds in datasets]
plt.plot(datasets, means, label=model)
plt.fill_between(datasets, np.array(means) - np.array(stds), np.array(means) + np.array(stds), alpha=0.1)
plt.ylabel("Accuracy (%)")
plt.title("Convex GNN Performance Across Datasets")
plt.legend(loc='upper left', bbox_to_anchor=(1, 1))
plt.tight_layout()
plt.savefig("line_plot_accuracy_trends.png")
plt.close()
# --- 2. Radar plots: one radar plot per convex model ---
from math import pi
def make_radar_plot(model_name):
values = [df.loc[model_name, (ds, 'mean')] for ds in datasets]
values += values[:1] # close the loop
angles = [n / float(len(datasets)) * 2 * pi for n in range(len(datasets))]
angles += angles[:1]
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
ax.plot(angles, values, linewidth=2, linestyle='solid', label=model_name)
ax.fill(angles, values, alpha=0.25)
ax.set_xticks(angles[:-1])
ax.set_xticklabels(datasets, fontsize=20)
ax.set_yticklabels([])
ax.set_title(model_name, fontsize=20)
plt.tight_layout()
plt.savefig(f"radar_plot_{model_name.replace(' ', '_')}.png")
plt.close()
for model in convex_models:
make_radar_plot(model)
# --- 3. Heatmap of mean accuracy values ---
new_labels = []
for label in df.index:
if label.startswith('C'):
new_labels.append(f"$\\bf{{{label}}}$") # bold via mathtext
else:
new_labels.append(label)
df.index = new_labels
# Set updated tick labels
mean_data = df.xs('mean', axis=1, level=1)
sns.heatmap(mean_data, annot=True, fmt=".1f", cmap="YlGnBu", linewidths=0.5, cbar_kws={'label': 'Accuracy (%)'})
plt.title("Accuracy Heatmap Across Models and Datasets")
plt.ylabel("Model")
plt.xlabel("Dataset")
plt.tight_layout()
plt.savefig("heatmap_model_vs_dataset.png")
plt.close()