Commit 15b183a24d4fa0c2e97c2239e8a132470a6749b1

Authored by Mathias
1 parent 503bfd9274
Exists in master

Add purity measure to the script

Showing 1 changed file with 15 additions and 2 deletions Side-by-side Diff

scripts/evaluations/clustering.py
... ... @@ -18,7 +18,7 @@
18 18 import matplotlib.pyplot as plt
19 19  
20 20 from volia.data_io import read_features,read_lst
21   -from volia.measures import entropy_score
  21 +from volia.measures import entropy_score, purity_score
22 22  
23 23 '''
24 24 TODO:
... ... @@ -77,6 +77,12 @@
77 77 # V-Measure
78 78 v_measure = v_measure_score(labels, predicted_labels)
79 79  
  80 + # Purity
  81 + purity_scores = purity_score(labels, predicted_labels)
  82 + purity_class_score = purity_scores["purity_class_score"]
  83 + purity_cluster_score = purity_scores["purity_cluster_score"]
  84 + K = purity_scores["K"]
  85 +
80 86 # Write results
81 87 with open(os.path.join(outdir, f"_" + args.prefix + "eval_clustering.log"), "w") as fd:
82 88 print(f"F1-scores for each classes:\n{fscores_str}", file=fd)
... ... @@ -85,6 +91,9 @@
85 91 print(f"Homogeneity: {homogeneity}", file=fd)
86 92 print(f"completeness: {completeness}", file=fd)
87 93 print(f"v-measure: {v_measure}", file=fd)
  94 + print(f"purity class score: {purity_class_score}", file=fd)
  95 + print(f"purity cluster score: {purity_cluster_score}", file=fd)
  96 + print(f"purity overall evaluation criterion (K): {K}", file=fd)
88 97  
89 98 # Process t-SNE and plot
90 99 tsne_estimator = TSNE()
91 100  
... ... @@ -128,8 +137,12 @@
128 137 "entropy": entropy,
129 138 "homogeneity": homogeneity,
130 139 "completeness": completeness,
131   - "v-measure": v_measure
  140 + "v-measure": v_measure,
  141 + "purity_class_score": purity_class_score,
  142 + "purity_cluster score": purity_cluster_score,
  143 + "K": K
132 144 }
  145 +
133 146  
134 147 if __name__ == "__main__":
135 148 # Argparse