Add consistent comparative results to reports

This commit is contained in:
2022-10-25 15:00:37 +02:00
parent 29c4b4ceef
commit b24a508d1c
18 changed files with 75 additions and 29 deletions

View File

@@ -9,16 +9,37 @@ import xlsxwriter
import numpy as np import numpy as np
from .Experiments import BestResults from .Experiments import BestResults
from .Datasets import Datasets from .Datasets import Datasets
from .Arguments import EnvData, ALL_METRICS
from .Utils import ( from .Utils import (
Folders, Folders,
Files, Files,
Symbols, Symbols,
BEST_ACCURACY_STREE,
TextColor, TextColor,
NO_RESULTS, NO_RESULTS,
) )
class BestResultsEver:
def __init__(self):
self.data = {}
for i in ["Tanveer", "Surcov", "Arff"]:
self.data[i] = {}
for metric in ALL_METRICS:
self.data[i][metric.replace("-", "_")] = ["self", 1.0]
self.data[i][metric] = ["self", 1.0]
self.data["Tanveer"]["accuracy"] = [
"STree_default (liblinear-ovr)",
40.282203,
]
self.data["Arff"]["accuracy"] = [
"STree_default (linear-ovo)",
21.9765,
]
def get_name_value(self, key, score):
return self.data[key][score]
class BaseReport(abc.ABC): class BaseReport(abc.ABC):
def __init__(self, file_name, best_file=False): def __init__(self, file_name, best_file=False):
self.file_name = file_name self.file_name = file_name
@@ -30,7 +51,20 @@ class BaseReport(abc.ABC):
with open(self.file_name) as f: with open(self.file_name) as f:
self.data = json.load(f) self.data = json.load(f)
self.best_acc_file = best_file self.best_acc_file = best_file
self.lines = self.data if best_file else self.data["results"] if best_file:
self.lines = self.data
else:
self.lines = self.data["results"]
self.score_name = self.data["score_name"]
self.__compute_best_results_ever()
def __compute_best_results_ever(self):
args = EnvData.load()
key = args["source_data"]
best = BestResultsEver()
self.best_score_name, self.best_score_value = best.get_name_value(
key, self.score_name
)
def _get_accuracy(self, item): def _get_accuracy(self, item):
return self.data[item][0] if self.best_acc_file else item["score"] return self.data[item][0] if self.best_acc_file else item["score"]
@@ -69,6 +103,12 @@ class BaseReport(abc.ABC):
} }
return meaning[status] return meaning[status]
def _get_best_accuracy(self):
return self.best_score_value
def _get_message_best_accuracy(self):
return f"{self.score_name} compared to {self.best_score_name} .:"
@abc.abstractmethod @abc.abstractmethod
def header(self) -> None: def header(self) -> None:
pass pass
@@ -188,8 +228,8 @@ class Report(BaseReport):
f" {key} {self._status_meaning(key)} .....: {value:2d}" f" {key} {self._status_meaning(key)} .....: {value:2d}"
) )
self.header_line( self.header_line(
f" Accuracy compared to stree_default (liblinear-ovr) .: " f" {self._get_message_best_accuracy()} "
f"{accuracy/BEST_ACCURACY_STREE:7.4f}" f"{accuracy/self._get_best_accuracy():7.4f}"
) )
self.header_line("*") self.header_line("*")
@@ -209,12 +249,12 @@ class ReportBest(BaseReport):
if best if best
else Files.grid_output(score, model) else Files.grid_output(score, model)
) )
file_name = os.path.join(Folders.results, name)
self.best = best self.best = best
self.grid = grid self.grid = grid
file_name = os.path.join(Folders.results, name)
super().__init__(file_name, best_file=True)
self.score_name = score self.score_name = score
self.model = model self.model = model
super().__init__(file_name, best_file=True)
def header_line(self, text: str) -> None: def header_line(self, text: str) -> None:
length = sum(self.header_lengths) + len(self.header_lengths) - 3 length = sum(self.header_lengths) + len(self.header_lengths) - 3
@@ -254,8 +294,8 @@ class ReportBest(BaseReport):
def footer(self, accuracy): def footer(self, accuracy):
self.header_line("*") self.header_line("*")
self.header_line( self.header_line(
f" Scores compared to stree_default accuracy (liblinear-ovr) .: " f" {self._get_message_best_accuracy()} "
f"{accuracy/BEST_ACCURACY_STREE:7.4f}" f"{accuracy/self._get_best_accuracy():7.4f}"
) )
self.header_line("*") self.header_line("*")
@@ -509,8 +549,8 @@ class Excel(BaseReport):
self.sheet.write(self.row, 3, self._status_meaning(key), bold) self.sheet.write(self.row, 3, self._status_meaning(key), bold)
self.row += 1 self.row += 1
message = ( message = (
f"** Accuracy compared to stree_default (liblinear-ovr) .: " f"** {self._get_message_best_accuracy()} "
f"{accuracy/BEST_ACCURACY_STREE:7.4f}" f"{accuracy/self._get_best_accuracy():7.4f}"
) )
bold = self.book.add_format({"bold": True, "font_size": 14}) bold = self.book.add_format({"bold": True, "font_size": 14})
# set width of the hyperparams column with the maximum width # set width of the hyperparams column with the maximum width
@@ -634,6 +674,13 @@ class Benchmark:
self._report = {} self._report = {}
self._datasets = set() self._datasets = set()
self.visualize = visualize self.visualize = visualize
self.__compute_best_results_ever()
def __compute_best_results_ever(self):
args = EnvData.load()
key = args["source_data"]
best = BestResultsEver()
_, self.best_score_value = best.get_name_value(key, self._score)
def get_result_file_name(self): def get_result_file_name(self):
return os.path.join(Folders.exreport, Files.exreport(self._score)) return os.path.join(Folders.exreport, Files.exreport(self._score))
@@ -971,7 +1018,7 @@ class Benchmark:
sheet.write_formula( sheet.write_formula(
row, row,
col + 1, col + 1,
f"=sum({range_metric})/{BEST_ACCURACY_STREE}", f"=sum({range_metric})/{self.best_score_value}",
decimal_total, decimal_total,
) )
range_rank = ( range_rank = (
@@ -1063,7 +1110,7 @@ class StubReport(BaseReport):
def footer(self, accuracy: float) -> None: def footer(self, accuracy: float) -> None:
self.accuracy = accuracy self.accuracy = accuracy
self.score = accuracy / BEST_ACCURACY_STREE self.score = accuracy / self._get_best_accuracy()
class Summary: class Summary:

View File

@@ -1,7 +1,6 @@
import os import os
import subprocess import subprocess
BEST_ACCURACY_STREE = 40.282203
NO_RESULTS = "** No results found **" NO_RESULTS = "** No results found **"
NO_ENV = "File .env not found" NO_ENV = "File .env not found"

View File

@@ -7,5 +7,5 @@ Dataset Score File/Message
balance-scale 0.963520 results_accuracy_ODTE_Galgo_2022-04-20_10:52:20_0.json {'base_estimator__C': 57, 'base_estimator__gamma': 0.1, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1} balance-scale 0.963520 results_accuracy_ODTE_Galgo_2022-04-20_10:52:20_0.json {'base_estimator__C': 57, 'base_estimator__gamma': 0.1, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1}
balloons 0.785000 results_accuracy_ODTE_Galgo_2022-04-20_10:52:20_0.json {'base_estimator__C': 5, 'base_estimator__gamma': 0.14, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1} balloons 0.785000 results_accuracy_ODTE_Galgo_2022-04-20_10:52:20_0.json {'base_estimator__C': 5, 'base_estimator__gamma': 0.14, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1}
****************************************************************************************************************************************************************** ******************************************************************************************************************************************************************
* Scores compared to stree_default accuracy (liblinear-ovr) .: 0.0434 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0434 *
****************************************************************************************************************************************************************** ******************************************************************************************************************************************************************

View File

@@ -11,6 +11,6 @@ Dataset Sampl. Feat. Cls Nodes Leaves Depth Score
balance-scale 625 4 3 23.32 12.16 6.44 0.840160±0.0304 0.013745±0.0019 {'splitter': 'best', 'max_features': 'auto'} balance-scale 625 4 3 23.32 12.16 6.44 0.840160±0.0304 0.013745±0.0019 {'splitter': 'best', 'max_features': 'auto'}
balloons 16 4 2 3.00 2.00 2.00 0.860000±0.2850 0.000388±0.0000 {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'} balloons 16 4 2 3.00 2.00 2.00 0.860000±0.2850 0.000388±0.0000 {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}
************************************************************************************************************************ ************************************************************************************************************************
* Accuracy compared to stree_default (liblinear-ovr) .: 0.0422 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0422 *
************************************************************************************************************************ ************************************************************************************************************************
Results in results/results_accuracy_STree_iMac27_2022-05-09_00:15:25_0.json Results in results/results_accuracy_STree_iMac27_2022-05-09_00:15:25_0.json

View File

@@ -11,6 +11,6 @@ Dataset Sampl. Feat. Cls Nodes Leaves Depth Score
balance-scale 625 4 3 17.36 9.18 6.18 0.908480±0.0247 0.007388±0.0013 {} balance-scale 625 4 3 17.36 9.18 6.18 0.908480±0.0247 0.007388±0.0013 {}
balloons 16 4 2 4.64 2.82 2.66 0.663333±0.3009 0.000664±0.0002 {} balloons 16 4 2 4.64 2.82 2.66 0.663333±0.3009 0.000664±0.0002 {}
************************************************************************************************************************ ************************************************************************************************************************
* Accuracy compared to stree_default (liblinear-ovr) .: 0.0390 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0390 *
************************************************************************************************************************ ************************************************************************************************************************
Results in results/results_accuracy_STree_iMac27_2022-05-08_20:14:43_0.json Results in results/results_accuracy_STree_iMac27_2022-05-08_20:14:43_0.json

View File

@@ -10,6 +10,6 @@ Dataset Sampl. Feat. Cls Nodes Leaves Depth Score
============================== ====== ===== === ======= ======= ======= =============== ================ =============== ============================== ====== ===== === ======= ======= ======= =============== ================ ===============
balloons 16 4 2 4.64 2.82 2.66 0.663333±0.3009 0.000671±0.0001 {} balloons 16 4 2 4.64 2.82 2.66 0.663333±0.3009 0.000671±0.0001 {}
************************************************************************************************************************ ************************************************************************************************************************
* Accuracy compared to stree_default (liblinear-ovr) .: 0.0165 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0165 *
************************************************************************************************************************ ************************************************************************************************************************
Partial result file removed: results/results_accuracy_STree_iMac27_2022-05-08_19:38:28_0.json Partial result file removed: results/results_accuracy_STree_iMac27_2022-05-08_19:38:28_0.json

View File

@@ -11,6 +11,6 @@ Dataset Sampl. Feat. Cls Nodes Leaves Depth Score
balance-scale 625 4 3 26.12 13.56 7.94 0.910720±0.0249 0.015852±0.0027 {'C': 1.0, 'kernel': 'liblinear', 'multiclass_strategy': 'ovr'} balance-scale 625 4 3 26.12 13.56 7.94 0.910720±0.0249 0.015852±0.0027 {'C': 1.0, 'kernel': 'liblinear', 'multiclass_strategy': 'ovr'}
balloons 16 4 2 4.64 2.82 2.66 0.663333±0.3009 0.000640±0.0001 {'C': 1.0, 'kernel': 'linear', 'multiclass_strategy': 'ovr'} balloons 16 4 2 4.64 2.82 2.66 0.663333±0.3009 0.000640±0.0001 {'C': 1.0, 'kernel': 'linear', 'multiclass_strategy': 'ovr'}
************************************************************************************************************************ ************************************************************************************************************************
* Accuracy compared to stree_default (liblinear-ovr) .: 0.0391 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0391 *
************************************************************************************************************************ ************************************************************************************************************************
Results in results/results_accuracy_STree_iMac27_2022-05-09_00:21:06_0.json Results in results/results_accuracy_STree_iMac27_2022-05-09_00:21:06_0.json

View File

@@ -45,4 +45,4 @@
8;10;"0.0008541679382324218" 8;10;"0.0008541679382324218"
8;11;"3.629469326417878e-05" 8;11;"3.629469326417878e-05"
8;12;"{'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}" 8;12;"{'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}"
10;1;"** Accuracy compared to stree_default (liblinear-ovr) .: 0.0454" 10;1;"** accuracy compared to STree_default (liblinear-ovr) .: 0.0454"

View File

@@ -45,4 +45,4 @@
8;10;"0.1156062078475952" 8;10;"0.1156062078475952"
8;11;"0.0127842418285999" 8;11;"0.0127842418285999"
8;12;"{'base_estimator__C': 5, 'base_estimator__gamma': 0.14, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1}" 8;12;"{'base_estimator__C': 5, 'base_estimator__gamma': 0.14, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1}"
10;1;"** Accuracy compared to stree_default (liblinear-ovr) .: 0.0434" 10;1;"** accuracy compared to STree_default (liblinear-ovr) .: 0.0434"

View File

@@ -43,4 +43,4 @@
8;10;"0.02120100021362305" 8;10;"0.02120100021362305"
8;11;"0.003526023309468471" 8;11;"0.003526023309468471"
8;12;"{'splitter': 'best', 'max_features': 'auto'}" 8;12;"{'splitter': 'best', 'max_features': 'auto'}"
10;1;"** Accuracy compared to stree_default (liblinear-ovr) .: 0.0416" 10;1;"** accuracy compared to STree_default (liblinear-ovr) .: 0.0416"

View File

@@ -49,4 +49,4 @@
11;2;"✔" 11;2;"✔"
11;3;1 11;3;1
11;4;"Equal to best" 11;4;"Equal to best"
13;1;"** Accuracy compared to stree_default (liblinear-ovr) .: 0.0454" 13;1;"** accuracy compared to STree_default (liblinear-ovr) .: 0.0454"

View File

@@ -45,4 +45,4 @@
8;10;"0.1156062078475952" 8;10;"0.1156062078475952"
8;11;"0.0127842418285999" 8;11;"0.0127842418285999"
8;12;"{'base_estimator__C': 5, 'base_estimator__gamma': 0.14, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1}" 8;12;"{'base_estimator__C': 5, 'base_estimator__gamma': 0.14, 'base_estimator__kernel': 'rbf', 'base_estimator__multiclass_strategy': 'ovr', 'n_estimators': 100, 'n_jobs': -1}"
10;1;"** Accuracy compared to stree_default (liblinear-ovr) .: 0.0434" 10;1;"** accuracy compared to STree_default (liblinear-ovr) .: 0.0434"

View File

@@ -45,4 +45,4 @@
8;10;"0.07016648769378662" 8;10;"0.07016648769378662"
8;11;"0.002460508923990468" 8;11;"0.002460508923990468"
8;12;"{}" 8;12;"{}"
10;1;"** Accuracy compared to stree_default (liblinear-ovr) .: 0.0363" 10;1;"** accuracy compared to STree_default (liblinear-ovr) .: 0.0363"

View File

@@ -45,4 +45,4 @@
8;10;"0.0008541679382324218" 8;10;"0.0008541679382324218"
8;11;"3.629469326417878e-05" 8;11;"3.629469326417878e-05"
8;12;"{'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}" 8;12;"{'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}"
10;1;"** Accuracy compared to stree_default (liblinear-ovr) .: 0.0454" 10;1;"** accuracy compared to STree_default (liblinear-ovr) .: 0.0454"

View File

@@ -11,5 +11,5 @@ Dataset Sampl. Feat. Cls Nodes Leaves Depth Score
balance-scale 625 4 3 7.00 4.00 3.00 0.970560±0.0150 0.014049±0.0020 {'C': 10000.0, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'} balance-scale 625 4 3 7.00 4.00 3.00 0.970560±0.0150 0.014049±0.0020 {'C': 10000.0, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}
balloons 16 4 2 3.00 2.00 2.00 0.860000±0.2850 0.000854±0.0000 {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'} balloons 16 4 2 3.00 2.00 2.00 0.860000±0.2850 0.000854±0.0000 {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}
************************************************************************************************************************ ************************************************************************************************************************
* Accuracy compared to stree_default (liblinear-ovr) .: 0.0454 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0454 *
************************************************************************************************************************ ************************************************************************************************************************

View File

@@ -7,5 +7,5 @@ Dataset Score File/Message
balance-scale 0.980000 results_accuracy_STree_iMac27_2021-10-27_09:40:40_0.json {'splitter': 'best', 'max_features': 'auto'} balance-scale 0.980000 results_accuracy_STree_iMac27_2021-10-27_09:40:40_0.json {'splitter': 'best', 'max_features': 'auto'}
balloons 0.860000 results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'} balloons 0.860000 results_accuracy_STree_iMac27_2021-09-30_11:42:07_0.json {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}
****************************************************************************************************************************************************************** ******************************************************************************************************************************************************************
* Scores compared to stree_default accuracy (liblinear-ovr) .: 0.0457 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0457 *
****************************************************************************************************************************************************************** ******************************************************************************************************************************************************************

View File

@@ -12,5 +12,5 @@ Dataset Sampl. Feat. Cls Nodes Leaves Depth Score
balloons 16 4 2 3.00 2.00 2.00 0.860000±0.2850✔ 0.000854±0.0000 {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'} balloons 16 4 2 3.00 2.00 2.00 0.860000±0.2850✔ 0.000854±0.0000 {'C': 7, 'gamma': 0.1, 'kernel': 'rbf', 'max_iter': 10000.0, 'multiclass_strategy': 'ovr'}
************************************************************************************************************************ ************************************************************************************************************************
* ✔ Equal to best .....: 1 * * ✔ Equal to best .....: 1 *
* Accuracy compared to stree_default (liblinear-ovr) .: 0.0454 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0454 *
************************************************************************************************************************ ************************************************************************************************************************

View File

@@ -7,5 +7,5 @@ Dataset Score File/Message
balance-scale 0.919995 v. 1.2.4, Computed on Test on 2022-02-22 at 12:00:00 took 1s {'C': 1.0, 'kernel': 'liblinear', 'multiclass_strategy': 'ovr'} balance-scale 0.919995 v. 1.2.4, Computed on Test on 2022-02-22 at 12:00:00 took 1s {'C': 1.0, 'kernel': 'liblinear', 'multiclass_strategy': 'ovr'}
balloons 0.625000 v. 1.2.4, Computed on Test on 2022-02-22 at 12:00:00 took 1s {'C': 1.0, 'kernel': 'linear', 'multiclass_strategy': 'ovr'} balloons 0.625000 v. 1.2.4, Computed on Test on 2022-02-22 at 12:00:00 took 1s {'C': 1.0, 'kernel': 'linear', 'multiclass_strategy': 'ovr'}
****************************************************************************************************************************************************************** ******************************************************************************************************************************************************************
* Scores compared to stree_default accuracy (liblinear-ovr) .: 0.0384 * * accuracy compared to STree_default (liblinear-ovr) .: 0.0384 *
****************************************************************************************************************************************************************** ******************************************************************************************************************************************************************