From 3baacb5a042bd432d8a952ccc2497a05cf6c024f Mon Sep 17 00:00:00 2001
From: Pierre LOTTE <pierrelotte.dev@gmail.com>
Date: Mon, 30 Sep 2024 08:54:00 +0200
Subject: [PATCH] Change results structure

---
 results/base.py |  2 +-
 results/roc.py  | 12 ++++--------
 2 files changed, 5 insertions(+), 9 deletions(-)

diff --git a/results/base.py b/results/base.py
index 5f87b56..1790ed5 100644
--- a/results/base.py
+++ b/results/base.py
@@ -11,7 +11,7 @@ class BaseResults():
         self.path = path
         self.algos = algos
         self.configs = config_names
-        self.result = {"roc": {}, "f1": {}}
+        self.result = {}
 
     def compute(self, auto_split=False):
         """
diff --git a/results/roc.py b/results/roc.py
index 8c0c7e7..4b03993 100644
--- a/results/roc.py
+++ b/results/roc.py
@@ -38,25 +38,21 @@ class ROCResults(BaseResults):
                 roc, f1 = self.__compute_score(labels, y_pred_path)
 
                 if algo in self.result["roc"]:
-                    self.result["roc"][algo][config_name] = {"classic": round(roc, 4)}
-                    self.result["f1"][algo][config_name] = {"classic": round(f1, 4)}
+                    self.result[algo][config_name] = {"classic": {"roc": round(roc, 4), "f1": round(f1, 4)}}
                 else:
-                    self.result["roc"][algo] = {config_name: {"classic": round(roc, 4)}}
-                    self.result["f1"][algo] = {config_name: {"classic": round(f1, 4)}}
+                    self.result[algo] = {config_name: {"classic": {"roc": round(roc, 4), "f1": round(f1, 4)}}}
 
                 # Compute results for automatically splitted dataset
                 if auto_split:
                     files = __exec(f"find -L {self.path}/{config_name}/results_{algo} -regex '^.*dataset[_0-9]+_auto_split_{algo}.ts'")
                     roc, f1 = self.__compute_score(labels, files, local=True)
-                    self.result["roc"][algo][f"{config_name}"]["auto_split"] = round(roc, 4)
-                    self.result["f1"][algo][f"{config_name}"]["auto_split"] = round(f1, 4)
+                    self.result[algo][f"{config_name}"]["auto_split"] = {"roc": round(roc, 4), "f1": round(f1, 4)}
 
                 # Compute results for splitted dataset
                 files = __exec(f"find -L {self.path}/{config_name}/results_{algo} -regex '^.*dataset[_0-9]+_{algo}.ts'")
 
                 roc, f1 = self.__compute_score(labels, files, local=True)
-                self.result["roc"][algo][f"{config_name}"]["split"] = round(roc, 4)
-                self.result["f1"][algo][f"{config_name}"]["split"] = round(f1, 4)
+                self.result[algo][f"{config_name}"]["split"] = {"roc": round(roc, 4), "f1": round(f1, 4)}
 
         print(json.dumps(self.result))
 
-- 
GitLab