From 21d052313c5d6d401878251cbd7edaf87464d7b0 Mon Sep 17 00:00:00 2001 From: Alejandro Moreo Date: Wed, 3 Apr 2024 16:24:55 +0200 Subject: [PATCH] showing experiments --- Census/adjacentconcat_4.py | 2 +- Census/adjacentmedianoptim_4.2.py | 4 +++- Census/allconcat_3.py | 4 +++- Census/classification_accuracy_1.py | 11 +++++++---- Census/commons.py | 4 ++-- Census/pairwise_2.py | 5 ++++- Census/table.py | 10 +++++++--- 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Census/adjacentconcat_4.py b/Census/adjacentconcat_4.py index 50e25eb..25c9d11 100644 --- a/Census/adjacentconcat_4.py +++ b/Census/adjacentconcat_4.py @@ -52,7 +52,7 @@ methods = [f'{q_name}-cat' for q_name in q_names] table = Table(name='adjacentconcat', benchmarks=benchmarks, methods=methods, stat_test=None, color_mode='local') table.format.mean_prec = 4 table.format.show_std = False -table.format.sta = False +# table.format = False table.format.remove_zero = True for q_name, q in quantifiers(): diff --git a/Census/adjacentmedianoptim_4.2.py b/Census/adjacentmedianoptim_4.2.py index 77ef33a..ff69b44 100644 --- a/Census/adjacentmedianoptim_4.2.py +++ b/Census/adjacentmedianoptim_4.2.py @@ -14,9 +14,11 @@ from copy import deepcopy np.set_printoptions(linewidth=np.inf) + def classifier(): return LogisticRegression() + def quantifiers(): cls = classifier() # yield 'MLPE', MLPE() @@ -26,7 +28,7 @@ def quantifiers(): yield 'PACC', PACC(cls) yield 'MS', MS(cls) # yield 'MS2', MS2(cls) - # yield 'SLD', EMQ(cls) + yield 'SLD', EMQ(cls) survey_y = './data/survey_y.csv' diff --git a/Census/allconcat_3.py b/Census/allconcat_3.py index b974b29..7501b32 100644 --- a/Census/allconcat_3.py +++ b/Census/allconcat_3.py @@ -12,9 +12,11 @@ import quapy as qp np.set_printoptions(linewidth=np.inf) + def classifier(): return LogisticRegressionCV() + def quantifiers(): cls = classifier() yield 'MLPE', MLPE() @@ -50,7 +52,7 @@ methods = [f'{q_name}-cat' for q_name in q_names] table = Table(name='allconcat', benchmarks=benchmarks, methods=methods, stat_test=None, color_mode='local') table.format.mean_prec = 4 table.format.show_std = False -table.format.sta = False +table.format.stat_test = False table.format.remove_zero = True for q_name, q in quantifiers(): diff --git a/Census/classification_accuracy_1.py b/Census/classification_accuracy_1.py index 3354f84..ec07235 100644 --- a/Census/classification_accuracy_1.py +++ b/Census/classification_accuracy_1.py @@ -1,15 +1,18 @@ import numpy as np -from sklearn.svm import SVC +from sklearn.linear_model import LogisticRegressionCV, LogisticRegression +from sklearn.svm import SVC, LinearSVC from commons import * from table import Table +from tqdm import tqdm np.set_printoptions(linewidth=np.inf) def classifiers(): - yield 'LR-opt', LogisticRegressionCV(class_weight='balanced', Cs=10) - yield 'LR-def', LogisticRegressionCV() + yield 'LR-opt', LogisticRegressionCV(Cs=10) + yield 'LR-opt-bal', LogisticRegressionCV(class_weight='balanced', Cs=10) + yield 'LR-def', LogisticRegression() yield 'SVM-linear', LinearSVC() yield 'SVM-rbf', SVC(kernel='rbf') @@ -37,7 +40,7 @@ for cls_name, c in classifiers(): table = Table(name=cls_name, benchmarks=benchmarks, methods=methods, stat_test=None, color_mode='local', lower_is_better=False) table.format.mean_prec = 4 table.format.show_std = False - table.format.sta = False + table.format.stat_test = False table.format.remove_zero = True for i, (Ai, Xi, yi) in tqdm(enumerate(trains), total=n_areas): diff --git a/Census/commons.py b/Census/commons.py index 66ac393..3d6118c 100644 --- a/Census/commons.py +++ b/Census/commons.py @@ -18,8 +18,8 @@ def load_csv(file, use_yhat=True): X = df[covariates].values A = df[cod_area].values - # for i, cov in enumerate(covariates): - # print(f'values of col {i} "{cov}" {np.unique(X[:,i])}') + for i, cov in enumerate(covariates): + print(f'values of col {i} "{cov}" {np.unique(X[:,i])}') if y_true in df.columns: y = df[y_true].values diff --git a/Census/pairwise_2.py b/Census/pairwise_2.py index d96d94f..e1708dd 100644 --- a/Census/pairwise_2.py +++ b/Census/pairwise_2.py @@ -3,7 +3,7 @@ from sklearn.linear_model import LogisticRegressionCV from quapy.data import LabelledCollection from quapy.method.non_aggregative import MaximumLikelihoodPrevalenceEstimation as MLPE -from quapy.method.aggregative import CC, PCC, ACC, PACC, EMQ +from quapy.method.aggregative import CC, PCC, ACC, PACC, EMQ, SLD from commons import * from table import Table from tqdm import tqdm @@ -22,6 +22,7 @@ def quantifiers(): yield 'PCC', PCC(cls) yield 'ACC', ACC(cls) yield 'PACC', PACC(cls) + yield 'SLD', SLD(cls) survey_y = './data/survey_y.csv' @@ -69,6 +70,8 @@ for q_name, q in quantifiers(): for test in benchmarks: values = table.get_benchmark_values(test) table.add(benchmark=test, method='Best', v=min(values)) + table.add(benchmark=test, method='Worst', v=max(values)) + table.add(benchmark=test, method='AVE', v=np.mean(values)) tables.append(table) diff --git a/Census/table.py b/Census/table.py index 25f4f11..0993a4d 100644 --- a/Census/table.py +++ b/Census/table.py @@ -430,7 +430,7 @@ class Table: return Table.LatexPDF(pdf_path, tables=[self], tabular_dir=tabular_dir, *args, **kwargs) @classmethod - def Document(self, tex_path, tables:List['Table'], tabular_dir='tables', *args, **kwargs): + def Document(self, tex_path, tables:List['Table'], tabular_dir='tables', landscape=True, *args, **kwargs): lines = [] lines.append('\\documentclass[10pt,a4paper]{article}') lines.append('\\usepackage[utf8]{inputenc}') @@ -440,11 +440,14 @@ class Table: lines.append('\\usepackage{graphicx}') lines.append('\\usepackage{xcolor}') lines.append('\\usepackage{colortbl}') + if landscape: + lines.append('\\usepackage[landscape]{geometry}') lines.append('') lines.append('\\begin{document}') for table in tables: lines.append('') lines.append(table.table(os.path.join(Path(tex_path).parent, tabular_dir, table.name + '_table.tex'), *args, **kwargs)) + lines.append('\n\\newpage\n') lines.append('\\end{document}') document = '\n'.join(lines) @@ -472,5 +475,6 @@ class Table: os.chdir(dir) os.system('pdflatex ' + Path(tex_path).name) basename = Path(tex_path).name.replace('.tex', '') - os.system(f'rm {basename}.aux {basename}.bbl {basename}.blg {basename}.log {basename}.out {basename}.dvi') - os.chdir(pwd) \ No newline at end of file + os.system(f'rm {basename}.aux {basename}.log') + os.chdir(pwd) + print('[Done]') \ No newline at end of file