forked from moreo/QuaPy
updating plots for submission
This commit is contained in:
parent
1aafd10e25
commit
95b21c8bc2
|
@ -33,6 +33,12 @@ def plot_error_by_drift(methods, error_name, logscale=False, path=None):
|
|||
if path is not None:
|
||||
path = join(path, f'error_by_drift_{error_name}.{plotext}')
|
||||
method_names, true_prevs, estim_prevs, tr_prevs = gather_results(methods, error_name)
|
||||
|
||||
method_order = ['SVM(AE)' if error_name=='ae' else 'SVM(RAE)',
|
||||
'PCC', 'SVM(KLD)', 'SVM(Q)', 'SVM(NKLD)', 'CC', 'HDy',
|
||||
'E(PACC)$_\\mathrm{Ptr}$',
|
||||
'E(PACC)$_\\mathrm{AE}$' if error_name=='ae' else 'E(PACC)$_\\mathrm{RAE}$',
|
||||
'QuaNet', 'PACC', 'ACC', 'SLD']
|
||||
qp.plot.error_by_drift(
|
||||
method_names,
|
||||
true_prevs,
|
||||
|
@ -43,7 +49,8 @@ def plot_error_by_drift(methods, error_name, logscale=False, path=None):
|
|||
show_std=False,
|
||||
logscale=logscale,
|
||||
title=f'Quantification error as a function of distribution shift',
|
||||
savepath=path
|
||||
savepath=path,
|
||||
method_order=method_order
|
||||
)
|
||||
|
||||
|
||||
|
@ -52,9 +59,15 @@ def diagonal_plot(methods, error_name, path=None):
|
|||
if path is not None:
|
||||
path = join(path, f'diag_{error_name}')
|
||||
method_names, true_prevs, estim_prevs, tr_prevs = gather_results(methods, error_name)
|
||||
qp.plot.binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=0, title='Negative', legend=False, show_std=False, savepath=f'{path}_neg.{plotext}')
|
||||
qp.plot.binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=1, title='Neutral', legend=False, show_std=False, savepath=f'{path}_neu.{plotext}')
|
||||
qp.plot.binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=2, title='Positive', legend=True, show_std=False, savepath=f'{path}_pos.{plotext}')
|
||||
method_order = ['SVM(AE)' if error_name == 'ae' else 'SVM(RAE)',
|
||||
'PCC', 'SVM(KLD)', 'SVM(Q)', 'SVM(NKLD)', 'CC', 'HDy',
|
||||
'E(PACC)$_\\mathrm{Ptr}$',
|
||||
'E(PACC)$_\\mathrm{AE}$' if error_name == 'ae' else 'E(PACC)$_\\mathrm{RAE}$',
|
||||
'QuaNet', 'PACC', 'ACC', 'SLD']
|
||||
qp.plot.binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=0, title='Negative', legend=False, show_std=False, savepath=f'{path}_neg.{plotext}', method_order=method_order)
|
||||
qp.plot.binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=1, title='Neutral', legend=False, show_std=False, savepath=f'{path}_neu.{plotext}', method_order=method_order)
|
||||
qp.plot.binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=2, title='Positive', legend=False, show_std=False, savepath=f'{path}_pos.{plotext}', method_order=method_order)
|
||||
qp.plot.binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=2, title='Positive', legend=True, show_std=False, savepath=f'{path}_pos.legend.{plotext}', method_order=method_order)
|
||||
|
||||
|
||||
def binary_bias_global(methods, error_name, path=None):
|
||||
|
@ -81,15 +94,15 @@ gao_seb_methods = ['cc', 'acc', 'pcc', 'pacc', 'sld', 'svmq', 'svmkld', 'svmnkld
|
|||
new_methods_ae = ['svmmae' , 'epaccmaeptr', 'epaccmaemae', 'hdy', 'quanet']
|
||||
new_methods_rae = ['svmmrae' , 'epaccmraeptr', 'epaccmraemrae', 'hdy', 'quanet']
|
||||
|
||||
plot_error_by_drift(gao_seb_methods+new_methods_ae, error_name='ae', path=plotdir)
|
||||
plot_error_by_drift(gao_seb_methods+new_methods_rae, error_name='rae', logscale=True, path=plotdir)
|
||||
# plot_error_by_drift(gao_seb_methods+new_methods_ae, error_name='ae', path=plotdir)
|
||||
# plot_error_by_drift(gao_seb_methods+new_methods_rae, error_name='rae', logscale=True, path=plotdir)
|
||||
|
||||
diagonal_plot(gao_seb_methods+new_methods_ae, error_name='ae', path=plotdir)
|
||||
diagonal_plot(gao_seb_methods+new_methods_rae, error_name='rae', path=plotdir)
|
||||
|
||||
binary_bias_global(gao_seb_methods+new_methods_ae, error_name='ae', path=plotdir)
|
||||
binary_bias_global(gao_seb_methods+new_methods_rae, error_name='rae', path=plotdir)
|
||||
|
||||
# binary_bias_global(gao_seb_methods+new_methods_ae, error_name='ae', path=plotdir)
|
||||
# binary_bias_global(gao_seb_methods+new_methods_rae, error_name='rae', path=plotdir)
|
||||
#
|
||||
#binary_bias_bins(gao_seb_methods+new_methods_ae, error_name='ae', path=plotdir)
|
||||
#binary_bias_bins(gao_seb_methods+new_methods_rae, error_name='rae', path=plotdir)
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ if __name__ == '__main__':
|
|||
\\resizebox{\\textwidth}{!}{%
|
||||
\\begin{tabular}{|c||""" + ('c|' * nold_methods) + '|' + ('c|' * nnew_methods) + """} \hline
|
||||
& \multicolumn{""" + str(nold_methods) + """}{c||}{Methods tested in~\cite{Gao:2016uq}} &
|
||||
\multicolumn{""" + str(nnew_methods) + """}{c|}{} \\\\ \hline
|
||||
\multicolumn{""" + str(nnew_methods) + """}{c|}{Newly added methods} \\\\ \hline
|
||||
"""
|
||||
rowreplace={dataset: nicename(dataset) for dataset in datasets}
|
||||
colreplace={method: nicename(method, eval_name, side=True) for method in methods}
|
||||
|
|
|
@ -13,7 +13,7 @@ plt.rcParams['font.size'] = 16
|
|||
|
||||
|
||||
def binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=1, title=None, show_std=True, legend=True,
|
||||
train_prev=None, savepath=None):
|
||||
train_prev=None, savepath=None, method_order=None):
|
||||
fig, ax = plt.subplots()
|
||||
ax.set_aspect('equal')
|
||||
ax.grid()
|
||||
|
@ -21,7 +21,15 @@ def binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=1, title=No
|
|||
|
||||
method_names, true_prevs, estim_prevs = _merge(method_names, true_prevs, estim_prevs)
|
||||
|
||||
for method, true_prev, estim_prev in zip(method_names, true_prevs, estim_prevs):
|
||||
order = list(zip(method_names, true_prevs, estim_prevs))
|
||||
if method_order is not None:
|
||||
table = {method_name:[true_prev, estim_prev] for method_name, true_prev, estim_prev in order}
|
||||
order = [(method_name, *table[method_name]) for method_name in method_order]
|
||||
|
||||
cm = plt.get_cmap('tab20')
|
||||
NUM_COLORS = len(method_names)
|
||||
ax.set_prop_cycle(color=[cm(1. * i / NUM_COLORS) for i in range(NUM_COLORS)])
|
||||
for method, true_prev, estim_prev in order:
|
||||
true_prev = true_prev[:,pos_class]
|
||||
estim_prev = estim_prev[:,pos_class]
|
||||
|
||||
|
@ -44,8 +52,12 @@ def binary_diagonal(method_names, true_prevs, estim_prevs, pos_class=1, title=No
|
|||
|
||||
if legend:
|
||||
box = ax.get_position()
|
||||
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
|
||||
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||||
# ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
|
||||
# ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||||
# ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
|
||||
ax.legend(loc='lower center',
|
||||
bbox_to_anchor=(1, -0.5),
|
||||
ncol=(len(method_names)+1)//2)
|
||||
|
||||
save_or_show(savepath)
|
||||
|
||||
|
@ -161,7 +173,8 @@ def _merge(method_names, true_prevs, estim_prevs):
|
|||
def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, n_bins=20, error_name='ae', show_std=True,
|
||||
logscale=False,
|
||||
title=f'Quantification error as a function of distribution shift',
|
||||
savepath=None):
|
||||
savepath=None,
|
||||
method_order=None):
|
||||
|
||||
fig, ax = plt.subplots()
|
||||
ax.grid()
|
||||
|
@ -171,6 +184,7 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, n_bins=20, e
|
|||
|
||||
# join all data, and keep the order in which the methods appeared for the first time
|
||||
data = defaultdict(lambda:{'x':np.empty(shape=(0)), 'y':np.empty(shape=(0))})
|
||||
if method_order is None:
|
||||
method_order = []
|
||||
for method, test_prevs_i, estim_prevs_i, tr_prev_i in zip(method_names, true_prevs, estim_prevs, tr_prevs):
|
||||
tr_prev_i = np.repeat(tr_prev_i.reshape(1,-1), repeats=test_prevs_i.shape[0], axis=0)
|
||||
|
@ -184,10 +198,15 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, n_bins=20, e
|
|||
if method not in method_order:
|
||||
method_order.append(method)
|
||||
|
||||
print(method_order)
|
||||
bins = np.linspace(0, 1, n_bins+1)
|
||||
binwidth = 1 / n_bins
|
||||
min_x, max_x = None, None
|
||||
for method in method_order:
|
||||
min_y, max_y = None, None
|
||||
cm = plt.get_cmap('tab20')
|
||||
NUM_COLORS = len(method_order)
|
||||
ax.set_prop_cycle(color=[cm(1. * i / NUM_COLORS) for i in range(NUM_COLORS)])
|
||||
for i,method in enumerate(method_order):
|
||||
tr_test_drifts = data[method]['x']
|
||||
method_drifts = data[method]['y']
|
||||
if logscale:
|
||||
|
@ -198,7 +217,7 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, n_bins=20, e
|
|||
for ind in range(len(bins)):
|
||||
selected = inds==ind
|
||||
if selected.sum() > 0:
|
||||
xs.append(ind*binwidth)
|
||||
xs.append(ind*binwidth-binwidth/2)
|
||||
ys.append(np.mean(method_drifts[selected]))
|
||||
ystds.append(np.std(method_drifts[selected]))
|
||||
|
||||
|
@ -207,10 +226,14 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, n_bins=20, e
|
|||
ystds = np.asarray(ystds)
|
||||
|
||||
min_x_method, max_x_method = xs.min(), xs.max()
|
||||
min_y_method, max_y_method = ys.min(), ys.max()
|
||||
min_x = min_x_method if min_x is None or min_x_method < min_x else min_x
|
||||
max_x = max_x_method if max_x is None or max_x_method > max_x else max_x
|
||||
min_y = min_y_method if min_y is None or min_y_method < min_y else min_y
|
||||
max_y = max_y_method if max_y is None or max_y_method > max_y else max_y
|
||||
|
||||
ax.errorbar(xs, ys, fmt='-', marker='o', label=method, markersize=3, zorder=2)
|
||||
marker = 'o' #if i < 10 else '^'
|
||||
ax.errorbar(xs, ys, fmt='-', marker=marker, label=method, markersize=6, zorder=2, linewidth=2.5)
|
||||
if show_std:
|
||||
ax.fill_between(xs, ys-ystds, ys+ystds, alpha=0.25)
|
||||
|
||||
|
@ -221,6 +244,8 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs, n_bins=20, e
|
|||
ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
|
||||
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
|
||||
ax.set_xlim(min_x, max_x)
|
||||
ax.fill_between([0.02, 0.1055], min_y, max_y,
|
||||
facecolor='green', alpha=0.25)
|
||||
|
||||
save_or_show(savepath)
|
||||
|
||||
|
|
Loading…
Reference in New Issue