def nemenyi_unrolled_plot(data, ylabel, xlabel, k_cv=1, rot=0, **set_fig_kwargs): nem = pd.DataFrame(columns=['means', 'l_b', 'u_b']) models = data.columns for i in np.unique(data.index): d_i = data.loc[data.index == i] ranks_means, ranks_intervals, fr_p_val, fr_stat, are_identical = nemenyi( d_i.values, k_cv=k_cv) print('index {}, are identical: {}, Fr. p_val:{}'.format( i, are_identical, fr_p_val)) nem_i_dat = np.hstack([ranks_means.reshape(-1, 1), ranks_intervals.T]) nem_i = pd.DataFrame(nem_i_dat, columns=['means', 'l_b', 'u_b'], index=np.tile(i, len(models))) nem_i = pd.concat( [nem_i, pd.Series(models, name='model', index=nem_i.index)], axis=1) nem = pd.concat([nem, nem_i], axis=0) fig, ax = set_figure(**set_fig_kwargs) cm = plt.get_cmap('plasma', len(models) * 2) for i, ind in enumerate(np.unique(data.index)): nem_i = nem.loc[nem.index == ind] for j, m in enumerate(models): nem_i_m = nem_i.loc[nem_i['model'] == m] x = i + j / (len(models) * 1.2) - 0.5 w = 0.8 / len(models) plt.bar(x, nem_i_m['u_b'] - nem_i_m['l_b'], bottom=nem_i_m['l_b'], color=cm(j), width=w, alpha=0.3) plt.scatter(x, nem_i_m['means'], marker='d', color=cm(j), s=w * 50 / len(np.unique(data.index))) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) ax.set_xticks(np.arange(len(np.unique(data.index)))) ax.set_xticklabels(np.unique(data.index), rotation=rot) y_min = nem['l_b'].min() * (1 - np.sign(nem['l_b'].min()) * 0.1) - 0.2 y_max = np.max(nem['u_b'].max()) * (1 + np.sign(nem['u_b'].max()) * 0.1) ax.set_ylim(y_min, y_max) plt.legend(models, loc='upper right', fontsize='x-small') return fig, ax
axis=1) fourier_mins.columns = [ 'mape w.r.t. mimo, Fourier', 'mape w.r.t. miso, Fourier', 'rmse w.r.t. mimo, Fourier', 'rmse w.r.t. miso, Fourier' ] mape_comparison = pd.concat([ res.loc[:, ['mape wrt mimo', 'mape wrt miso']], fourier_mins. loc[:, ['mape w.r.t. mimo, Fourier', 'mape w.r.t. miso, Fourier']] ]) rmse_comparison = pd.concat([ res.loc[:, ['rmse wrt mimo', 'rmse wrt miso']], fourier_mins. loc[:, ['rmse w.r.t. mimo, Fourier', 'rmse w.r.t. miso, Fourier']] ]) fig, ax = set_figure(size, (2, 1), font_scale=font_scale, w=0, h=0, sharex=True) sb.kdeplot(data=mape_comparison, ax=ax[0]) sb.kdeplot(data=rmse_comparison, ax=ax[1]) ax[0].vlines(1, *ax[0].get_ylim(), linewidth=1.5, color='k', linestyle='--') ax[1].vlines(1, *ax[1].get_ylim(), linewidth=1.5, color='k', linestyle='--') plt.savefig('figs/m4_regression.pdf') plt.show() lw = 1 s = 5 alpha = 0.1 # get terminal stages pdfs, pdfs_idx = pd.DataFrame({}), pd.DataFrame({})
]).T / results_k['rmse_miso'] res_miso[k] = pd.concat([mape, rmse], axis=1) mape = pd.DataFrame(results_k['mape'], index=['mape' ]).T / results_k['mape_mimo'] rmse = pd.DataFrame(results_k['rmse'], index=['rmse' ]).T / results_k['rmse_mimo'] res_mimo[k] = pd.concat([mape, rmse], axis=1) rmse_miso[k] = results_k['rmse_miso'] mape_miso[k] = results_k['mape_miso'] rmse_mimo[k] = results_k['rmse_mimo'] mape_mimo[k] = results_k['mape_mimo'] fig, ax = set_figure(size, (2, 2), font_scale=font_scale, w=0, h=0) lw = 2 s = 10 alpha = 0.3 t = np.asanyarray(list([res_mimo.values()][0])[0]['mape'].keys()) cm = plt.get_cmap('plasma', 256) for k, v in res_mimo.items(): color = np.minimum( 1, mape_mimo[k] / np.quantile(list(mape_mimo.values()), 0.9)) ax[0, 0].plot(t, v['mape'], color=cm(color), alpha=alpha) ax[0, 0].scatter(v.index[np.argmin(v['mape'])], np.min(v['mape']), color=cm(color), marker='o', s=s)
s = 5 alpha = 0.1 # get terminal stages pdfs, pdfs_idx = pd.DataFrame({}), pd.DataFrame({}) pdfs['mape_mimo'] = mimo_mins.loc[(slice(None), 'mape'), 'min'].values pdfs['mape_miso'] = miso_mins.loc[(slice(None), 'mape'), 'min'].values pdfs['rmse_mimo'] = mimo_mins.loc[(slice(None), 'rmse'), 'min'].values pdfs['rmse_miso'] = miso_mins.loc[(slice(None), 'rmse'), 'min'].values pdfs_idx['mape_mimo'] = mimo_mins.loc[(slice(None), 'mape'), 'idx'].values pdfs_idx['mape_miso'] = miso_mins.loc[(slice(None), 'mape'), 'idx'].values pdfs_idx['rmse_mimo'] = mimo_mins.loc[(slice(None), 'rmse'), 'idx'].values pdfs_idx['rmse_miso'] = miso_mins.loc[(slice(None), 'rmse'), 'idx'].values fig, ax = set_figure((5, 4), (2,2),font_scale=font_scale, w=0.25, h=0.35, l=0.1, r=0.8, t=0.95,b=0.2) # set distribution bars distplot_width = 0.05 dax = [] iax = [] sb.set_style('whitegrid') for i, a in enumerate(ax.ravel()): x0, y0, b_w, b_h = a.get_position().bounds dax.append(plt.axes([x0+b_w+0.01, y0, distplot_width, b_h])) dax[-1].set_xticks([]) dax[-1].set_yticks([]) sb.histplot(data=pdfs, y=pdfs.columns[i], element='step') sb.despine(ax=dax[-1]) dax[-1].hlines(1, *dax[-1].get_xlim()*np.array([0, 1.3]), linestyles='--', colors='gray', linewidth=lw)
import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sb from utils.cross_val import get_cv_results from analysis.plot_utils import set_figure size = (5, 4) font_scale = 0.7 results = np.load('data/hierarchical_scores.npy', allow_pickle=True) results = get_cv_results(results) results['mbt'] = results['mgb'] name = 'reconciliation_RMSE' f, ax = set_figure(size=size, subplots=(2, 1), w=0.3, h=0.2, b=0.2, font_scale=font_scale) results['bu']['type'] = results['bu'].index results['rec']['type'] = results['rec'].index results['mbt']['type'] = results['mgb'].index results['bu']['method'] = 'bu' results['rec']['method'] = 'rec' results['mbt']['method'] = 'mbt' res_k = pd.concat([results['bu'], results['rec'], results['mbt']]) sb.lineplot(x='sa', y='mape', data=res_k, hue='type', style='method', ax=ax[1]) ax[1].set_ylabel('MAPE [-]') plt.legend(fontsize='small', ncol=2,
results_meteo = get_cv_results(results_meteo) # pretty rename results['mbt lin meteo'] = results_meteo['mbt lin'] results['mbt meteo'] = results_meteo['mbt'] summary = OrderedDict({'rmse':{},'rmse_norm':{}}) for k,v in results.items(): if k in ['mbt', 'mbt meteo'] : continue summary['rmse'][k] = v['rmse'] summary['rmse_norm'][k] = v['norm_rmse'] f,ax = set_figure(size=size,w=0.3, h=0,b=0.2,font_scale=font_scale) summary = pd.DataFrame(summary) summary.reset_index(level=0, inplace=True) summary.rename(columns={'index':'model'}, inplace=True) summary = summary.melt('model',var_name='metric',value_name='RMSE [V]') sb.set_color_codes("pastel") sb.barplot(x='model', y='RMSE [V]', hue='metric', data=summary, linewidth=0.2) plt.savefig('figs/vsc_rmse.pdf') plt.show() # noise analysis results = np.load('data/vsc_results_meteo.npy', allow_pickle=True) cm = plt.get_cmap('plasma',10)