def test_plot_corr_grid(): hie_data = randhie.load_pandas() corr_matrix = np.corrcoef(hie_data.data.values.T) fig = plot_corr_grid([corr_matrix] * 2, xnames=hie_data.names) plt.close(fig) fig = plot_corr_grid([corr_matrix] * 5, xnames=[], ynames=hie_data.names) plt.close(fig) fig = plot_corr_grid([corr_matrix] * 3, normcolor=True, titles='', cmap='jet') plt.close(fig)
fig = plt.figure() for i, c in enumerate([rrcorr, corr_lw, corr_oas, corr_mcd]): #for i, c in enumerate([np.cov(rr, rowvar=0), cov_lw, cov_oas, cov_mcd]): ax = fig.add_subplot(2,2,i+1) plot_corr(c, xnames=None, title=titles[i], normcolor=normcolor, ax=ax) images = [c for ax in fig.axes for c in ax.get_children() if isinstance(c, mpl.image.AxesImage)] fig. subplots_adjust(bottom=0.1, right=0.9, top=0.9) cax = fig.add_axes([0.9, 0.1, 0.025, 0.8]) fig.colorbar(images[0], cax=cax) corrli = [rrcorr, corr_lw, corr_oas, corr_mcd, pcacorr] diffssq = np.array([[((ci-cj)**2).sum() for ci in corrli] for cj in corrli]) diffsabs = np.array([[np.max(np.abs(ci-cj)) for ci in corrli] for cj in corrli]) print(diffssq) print('\nmaxabs') print(diffsabs) fig.savefig('corrmatrix_sklearn.png', dpi=120) fig2 = plot_corr_grid(corrli+[residcorr], ncols=3, titles=titles+['pca', 'pca-residual'], xnames=[], ynames=[]) fig2.savefig('corrmatrix_sklearn_2.png', dpi=120) #plt.show() #plt.close('all')
ax = fig.add_subplot(2, 2, i + 1) plot_corr(c, xnames=None, title=titles[i], normcolor=normcolor, ax=ax) images = [ c for ax in fig.axes for c in ax.get_children() if isinstance(c, mpl.image.AxesImage) ] fig.subplots_adjust(bottom=0.1, right=0.9, top=0.9) cax = fig.add_axes([0.9, 0.1, 0.025, 0.8]) fig.colorbar(images[0], cax=cax) corrli = [rrcorr, corr_lw, corr_oas, corr_mcd, pcacorr] diffssq = np.array([[((ci - cj)**2).sum() for ci in corrli] for cj in corrli]) diffsabs = np.array([[np.max(np.abs(ci - cj)) for ci in corrli] for cj in corrli]) print diffssq print '\nmaxabs' print diffsabs fig.savefig('corrmatrix_sklearn.png', dpi=120) fig2 = plot_corr_grid(corrli + [residcorr], ncols=3, titles=titles + ['pca', 'pca-residual'], xnames=[], ynames=[]) fig2.savefig('corrmatrix_sklearn_2.png', dpi=120) #plt.show() #plt.close('all')
mcd.fit(rr, assume_centered=False) cov_mcd = mcd.covariance_ corr_mcd = cov2corr(cov_mcd) titles = ["raw correlation", "lw", "oas", "mcd"] normcolor = None fig = plt.figure() for i, c in enumerate([rrcorr, corr_lw, corr_oas, corr_mcd]): # for i, c in enumerate([np.cov(rr, rowvar=0), cov_lw, cov_oas, cov_mcd]): ax = fig.add_subplot(2, 2, i + 1) plot_corr(c, xnames=None, title=titles[i], normcolor=normcolor, ax=ax) images = [c for ax in fig.axes for c in ax.get_children() if isinstance(c, mpl.image.AxesImage)] fig.subplots_adjust(bottom=0.1, right=0.9, top=0.9) cax = fig.add_axes([0.9, 0.1, 0.025, 0.8]) fig.colorbar(images[0], cax=cax) corrli = [rrcorr, corr_lw, corr_oas, corr_mcd, pcacorr] diffssq = np.array([[((ci - cj) ** 2).sum() for ci in corrli] for cj in corrli]) diffsabs = np.array([[np.max(np.abs(ci - cj)) for ci in corrli] for cj in corrli]) print diffssq print "\nmaxabs" print diffsabs fig.savefig("corrmatrix_sklearn.png", dpi=120) fig2 = plot_corr_grid(corrli + [residcorr], ncols=3, titles=titles + ["pca", "pca-residual"], xnames=[], ynames=[]) fig2.savefig("corrmatrix_sklearn_2.png", dpi=120) # plt.show() # plt.close('all')