From 3b7e63994c7b1b562f19ca10c9c7b3b472483644 Mon Sep 17 00:00:00 2001 From: Mathias Date: Mon, 28 Sep 2020 14:24:13 +0200 Subject: [PATCH] Reajust the way to name files using prefix --- scripts/evaluations/clustering.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/evaluations/clustering.py b/scripts/evaluations/clustering.py index ead07be..7eba2ae 100644 --- a/scripts/evaluations/clustering.py +++ b/scripts/evaluations/clustering.py @@ -40,7 +40,7 @@ def train_clustering(label_encoder, feats, classes, outdir): estimator.fit(feats) print(f"Kmeans: processed {estimator.n_iter_} iterations - intertia={estimator.inertia_}") - with open(os.path.join(outdir, f"_kmeans.pkl"), "wb") as f: + with open(os.path.join(outdir, f"{args.prefix}kmeans.pkl"), "wb") as f: pickle.dump(estimator, f) # contains distance to each cluster for each sample @@ -84,7 +84,7 @@ def train_clustering(label_encoder, feats, classes, outdir): K = purity_scores["K"] # Write results - with open(os.path.join(outdir, f"_" + args.prefix + "eval_clustering.log"), "w") as fd: + with open(os.path.join(outdir, args.prefix + "eval_clustering.log"), "w") as fd: print(f"F1-scores for each classes:\n{fscores_str}", file=fd) print(f"Entropy: {entropy}", file=fd) print(f"Global score : {np.mean(fscores)}", file=fd) @@ -212,7 +212,7 @@ if __name__ == "__main__": # File with results - file_results = os.path.join(args.outdir, "clustering_measures.txt") + file_results = os.path.join(args.outdir, args.prefix + "clustering_measures.txt") with open(file_results, "w") as f: f.write(f"[nmodels: {args.nmodels}]\n") @@ -223,7 +223,7 @@ if __name__ == "__main__": f.write(f"[{key} => mean: {mean}, std: {std}] \n") # CSV File with all the values - file_csv_measures = os.path.join(args.outdir, "clustering_measures.csv") + file_csv_measures = os.path.join(args.outdir, args.prefix + "clustering_measures.csv") with open(file_csv_measures, "w", newline="") as f: writer = csv.writer(f, delimiter=",") -- 1.8.2.3