1
0
Fork 0

Merge pull request #16 from pglez82/protocols

Protocols
This commit is contained in:
Alejandro Moreo Fernandez 2023-01-18 16:55:51 +01:00 committed by GitHub
commit 3541f559e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import numpy as np
from matplotlib import cm from matplotlib import cm
from scipy.stats import ttest_ind_from_stats from scipy.stats import ttest_ind_from_stats
from matplotlib.ticker import ScalarFormatter from matplotlib.ticker import ScalarFormatter
import math
import quapy as qp import quapy as qp
@ -272,9 +273,8 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs,
if logscale: if logscale:
ax.set_yscale("log") ax.set_yscale("log")
ax.yaxis.set_major_formatter(ScalarFormatter()) ax.yaxis.set_major_formatter(ScalarFormatter())
ax.yaxis.set_minor_formatter(ScalarFormatter())
ax.yaxis.get_major_formatter().set_scientific(False) ax.yaxis.get_major_formatter().set_scientific(False)
ax.yaxis.get_minor_formatter().set_scientific(False) ax.minorticks_off()
inds = np.digitize(tr_test_drifts, bins, right=True) inds = np.digitize(tr_test_drifts, bins, right=True)
@ -306,13 +306,12 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs,
if show_density: if show_density:
ax2 = ax.twinx() ax2 = ax.twinx()
densities = npoints/np.sum(npoints)
ax2.bar([ind * binwidth-binwidth/2 for ind in range(len(bins))], ax2.bar([ind * binwidth-binwidth/2 for ind in range(len(bins))],
max_y*npoints/np.max(npoints), alpha=0.15, color='g', width=binwidth, label='density') densities, alpha=0.15, color='g', width=binwidth, label='density')
#ax2.set_ylabel("bar data") ax2.set_ylim(0,max(densities))
ax2.set_ylim(0,1)
ax2.spines['right'].set_color('g') ax2.spines['right'].set_color('g')
ax2.tick_params(axis='y', colors='g') ax2.tick_params(axis='y', colors='g')
#ax2.yaxis.set_visible(False)
ax.set(xlabel=f'Distribution shift between training set and test sample', ax.set(xlabel=f'Distribution shift between training set and test sample',
ylabel=f'{error_name.upper()} (true distribution, predicted distribution)', ylabel=f'{error_name.upper()} (true distribution, predicted distribution)',
@ -325,9 +324,15 @@ def error_by_drift(method_names, true_prevs, estim_prevs, tr_prevs,
ax.set_xlim(min_x, max_x) ax.set_xlim(min_x, max_x)
if logscale:
#nice scale for the logaritmic axis
ax.set_ylim(0,10 ** math.ceil(math.log10(max_y)))
if show_legend: if show_legend:
fig.legend(loc='right') fig.legend(loc='lower center',
bbox_to_anchor=(1, 0.5),
ncol=(len(method_names)+1)//2)
_save_or_show(savepath) _save_or_show(savepath)