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 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 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 plot_roc_curve(Y,n0=None,n1=None,smooth=False,no_plot=False,**ps): aucs = [] aucs_sd = [] if n0 is None: n0 = sum(Y==0) if n1 is None: n1 = sum(Y>0) for i,(title,p) in enumerate(sorted(ps.items())): fpr,tpr,auc = get_roc_curve(Y,p,smooth=smooth) aucs.append(auc) # Confidence Intervals for the Area under the ROC Curve # Cortes and Mohri # http://www.cs.nyu.edu/~mohri/pub/area.pdf m = n1 n = n0 A = auc Pxxy = 0 Pxyy = 0 iters = 10000 for j in range(iters): index = np.arange(len(Y)) np.random.shuffle(index) p_shuff = p[index] Y_shuff = Y[index] pa,pb = p_shuff[Y_shuff>0][0:2] na,nb = p_shuff[Y_shuff==0][0:2] Pxxy += ((pa>na) and (pb>na)) Pxyy += ((na<pa) and (nb<pa)) Pxxy/=iters Pxyy/=iters #print(A,Pxxy,Pxyy,m,n) var = (A*(1-A)+(m-1)*(Pxxy-(A**2))+(n-1)*(Pxyy-(A**2)))/(m*n) sd = np.sqrt(var) aucs_sd.append(sd) if not no_plot: plt.plot(fpr, tpr, lw=2, color=get_colors(i), label='%s = %0.2f' % (title,auc)) else: print('%s = %0.3f +/- %0.3f' % (title,auc,sd)) if not no_plot: plt.xlabel('False Positive Rate')#, fontsize='large', fontweight='bold') plt.ylabel('True Positive Rate')#, fontsize='large', fontweight='bold') plt.title('ROC curves')#, fontsize='large', fontweight='bold') plt.xticks()#fontsize='large', fontweight='bold') plt.yticks()#fontsize='large', fontweight='bold') plt.xlim(-0.01,1.01) plt.ylim(-0.01,1.01) plt.legend(loc="lower right",fontsize=17) return aucs,aucs_sd
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