def scatter_diag(props,ps,os,x_diag,y_diag,plot=True): from matplotlib.colors import Colormap as cmap imp = 'knn' xi = props.index(x_diag) yi = props.index(y_diag) p_x = ps[imp][xi,:,:].ravel() # Unravel all predictions of test data over all cv splits. p_y = ps[imp][yi,:,:].ravel() # Unravel all test data ground truth over all cv splits. o_x = os[imp][xi,:,:].ravel() # Unravel all predictions of test data over all cv splits. o_y = os[imp][yi,:,:].ravel() # Unravel all test data ground truth over all cv splits. mask = o_x.mask + o_y.mask p_x = p_x[mask==False] p_y = p_y[mask==False] o_x = o_x[mask==False] o_y = o_y[mask==False] colors = np.vstack((o_x.data,np.zeros(len(o_x)),o_y.data)).T colors[colors==0] = 0.2 if plot: plt.figure(figsize=(10,10)) plt.scatter(p_x+0.02*np.random.rand(p_pd.shape[0]), p_y+0.02*np.random.rand(p_pd.shape[0]), s=15, c=colors) plt.xlabel(x_diag) plt.ylabel(y_diag) plt.xlim(0,p_x.max()*1.05) plt.ylim(0,p_y.max()*1.05) plt.legend() return p_x,p_y,o_x,o_y
def plot_rocs(keys,uses,p_pos,Y,ys,smooth=True,no_plot=False): sns.set(font_scale=2) aucs = {} aucs_sd = {} for key in keys: if not no_plot: plt.figure() d = {use:p_pos[key][use]['average'] for use in uses} n0 = sum(Y[key]==0) n1 = sum(Y[key]>0) if n0==0 or n1==0: print("Missing either positive or negative examples of %s" % key) continue if ys[key].std()==0: print("Missing either positive or negative bootstrap examples of %s" % key) continue aucs[key],aucs_sd[key] = plot_roc_curve(ys[key],n0=n0,n1=n1,smooth=smooth,no_plot=no_plot,**d) for i,(a1,sd1) in enumerate(zip(aucs[key],aucs_sd[key])): for j,(a2,sd2) in enumerate(zip(aucs[key],aucs_sd[key])): if i>j: d = np.abs((a1-a2)/np.sqrt((sd1**2 + sd2**2)/2)) p = (1-norm.cdf(d,0,1))/2 print("\t%s vs %s: p=%.4f" % (sorted(uses)[i],sorted(uses)[j],p)) if not no_plot: plt.title(keys[key]) save_fig() return aucs,aucs_sd
def violin_roc(data): plt.figure(figsize=(15, 15)) sns.set_context("notebook", font_scale=2.5, rc={"lines.linewidth": 1.5, 'legend.fontsize': 20}) sns.violinplot(x='Predicted Probability', y='Diagnosis', hue='Outcome', data=data, split=True, inner="quart", palette={'--': "y", '+': "b"}, orient='h', width=1.0, scale='area',#count order=['VaD','Tauopathy NOS','AG','DLB','LB','ILBD', 'PD','AD','Parkinsonism NOS','PSP']) leg = plt.gca().get_legend() ltext = leg.get_texts() # all the text.Text instance in the legend plt.setp(ltext, fontsize=24) # the legend text fontsize plt.xlim(0,1) sns.despine(left=True)
def correct_corrs(tests, kind=None): matrix = correct_matrix(tests, kind=kind) for test in tests: if (test.subject.label is None) or (test.subject.label == kind): correct[test.subject]= [int(test.response_set.responses[i].correct) \ for i in range(1,41)] corrs = np.corrcoef(matrix.transpose()) plt.figure() plt.pcolor(np.arange(0.5,41.5,1),np.arange(0.5,41.5,1),corrs,cmap='RdBu_r',vmin=-1,vmax=1) plt.colorbar() plt.xlim(0.5,40.5) plt.ylim(0.5,40.5) return corrs