56 lines
1.4 KiB
Python
56 lines
1.4 KiB
Python
import numpy as np
|
|
import pandas as pd
|
|
|
|
from quapy.method.aggregative import EMQ, KDEyML, PACC
|
|
from sklearn.linear_model import LogisticRegression
|
|
|
|
METHODS = ['PACC',
|
|
'EMQ',
|
|
'KDEy-ML',
|
|
'KDEy-MLA'
|
|
]
|
|
|
|
|
|
# common hyperparameterss
|
|
hyper_LR = {
|
|
'classifier__C': np.logspace(-3, 3, 7),
|
|
'classifier__class_weight': ['balanced', None]
|
|
}
|
|
|
|
hyper_kde = {
|
|
'bandwidth': np.linspace(0.001, 0.5, 100)
|
|
}
|
|
|
|
hyper_kde_aitchison = {
|
|
'bandwidth': np.linspace(0.01, 2, 100)
|
|
}
|
|
|
|
# instances a new quantifier based on a string name
|
|
def new_method(method, **lr_kwargs):
|
|
lr = LogisticRegression(**lr_kwargs)
|
|
|
|
if method == 'KDEy-ML':
|
|
param_grid = {**hyper_kde, **hyper_LR}
|
|
quantifier = KDEyML(lr, kernel='gaussian')
|
|
elif method == 'KDEy-MLA':
|
|
param_grid = {**hyper_kde_aitchison, **hyper_LR}
|
|
quantifier = KDEyML(lr, kernel='aitchison')
|
|
elif method == 'EMQ':
|
|
param_grid = hyper_LR
|
|
quantifier = EMQ(lr)
|
|
elif method == 'PACC':
|
|
param_grid = hyper_LR
|
|
quantifier = PACC(lr)
|
|
else:
|
|
raise NotImplementedError('unknown method', method)
|
|
|
|
return param_grid, quantifier
|
|
|
|
|
|
def show_results(result_path):
|
|
df = pd.read_csv(result_path+'.csv', sep='\t')
|
|
|
|
pd.set_option('display.max_columns', None)
|
|
pd.set_option('display.max_rows', None)
|
|
pv = df.pivot_table(index='Dataset', columns="Method", values=["MAE", "MRAE"])
|
|
print(pv) |