-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensitivity_analysis.py
More file actions
73 lines (63 loc) · 2.36 KB
/
Copy pathsensitivity_analysis.py
File metadata and controls
73 lines (63 loc) · 2.36 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
import pandas as pd
import matplotlib.pyplot as plt
import os
# Updated list of datasets you're actually using
datasets = [
"npz_query",
"coauthorship_cora",
"cocitation_cora",
"cocitation_citeseer",
"npz_20news"
]
# Create output folder for plots
os.makedirs("plots", exist_ok=True)
# Optional: track best k values for each dataset
summary = []
for dataset in datasets:
filename = f"sensitivity_k_results_{dataset}.csv"
try:
df = pd.read_csv(filename)
# Plot 1: Clustering Quality
plt.figure(figsize=(10, 6))
plt.plot(df["k"], df["Accuracy"], label="Accuracy", marker="o")
plt.plot(df["k"], df["NMI"], label="NMI", marker="s")
plt.plot(df["k"], df["ARI"], label="ARI", marker="d")
plt.xscale("log")
plt.xlabel("k (log scale)")
plt.ylabel("Clustering Score")
plt.title(f"Impact of k on AHCKA Clustering Quality ({dataset})")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.savefig(f"plots/{dataset}_clustering_quality.png")
plt.close()
# Plot 2: Computational Efficiency
plt.figure(figsize=(10, 6))
plt.plot(df["k"], df["Runtime"], label="Runtime (s)", marker="o", color="red")
plt.plot(df["k"], df["Memory (MB)"], label="Memory Usage (MB)", marker="s", color="purple")
plt.xscale("log")
plt.xlabel("k (log scale)")
plt.ylabel("Resource Consumption")
plt.title(f"Impact of k on AHCKA Computational Efficiency ({dataset})")
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.savefig(f"plots/{dataset}_computational_efficiency.png")
plt.close()
print(f"✔️ Plots saved for '{dataset}' in 'plots/' folder.")
# Collect best k summary
best_row = df.loc[df["Accuracy"].idxmax()]
summary.append({
"Dataset": dataset,
"Best_k": int(best_row["k"]),
"Accuracy": best_row["Accuracy"],
"NMI": best_row["NMI"],
"ARI": best_row["ARI"],
})
except FileNotFoundError:
print(f"❌ File '{filename}' not found. Skipping...")
# Save summary if any
if summary:
summary_df = pd.DataFrame(summary)
summary_df.to_csv("plots/k_sensitivity_summary.csv", index=False)
print("\n📊 Summary of best k values saved to 'plots/k_sensitivity_summary.csv'")