Ejemplo n.º 1
0
def plot_cumul_hist(data, booklet=None):
    """
    Plots cumulative histogram for PPMI data.
    data: output of load()
    booklet: optionally restrict to one of four booklets (1-4).  
    """

    if booklet:
        smell = [value['upsit'][booklet - 1] for key, value in data.items()]
    else:
        smell = [sum(value['upsit']) for key, value in data.items()]
    recruitment = [value['recruitment'] for key, value in data.items()]

    smell_ctl = [
        smell[i] for i in range(len(recruitment)) if recruitment[i] == 0
    ]
    smell_ctl = sorted(smell_ctl)

    smell_pd = [
        smell[i] for i in range(len(recruitment)) if recruitment[i] == 1
    ]
    smell_pd = sorted(smell_pd)

    cumul_hist(smell_ctl, color='k')
    cumul_hist(smell_pd, color='r')

    plt.xlabel('UPSIT score')
    plt.ylabel('Cumulative Probability')
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
def plot_total_correct_cumul(X_total_correct,ctrl):
    X_ctrl = X_total_correct[ctrl == True,0]
    X_pd = X_total_correct[ctrl == False,0]
    plt.plot(sorted(X_ctrl),np.linspace(0,1,len(X_ctrl)),'k',label='Control')
    plt.plot(sorted(X_pd),np.linspace(0,1,len(X_pd)),'r',label='PD')
    plt.xlabel('Total Correct')
    plt.ylabel('Cumulative Probability')
    plt.legend(loc=2)
Ejemplo n.º 4
0
def plot_cumul(X,Y,label):
    X_pos = X[Y == True]
    X_neg = X[Y == False]
    plt.plot(sorted(X_neg),np.linspace(0,1,len(X_neg)),'k',label='-')
    plt.plot(sorted(X_pos),np.linspace(0,1,len(X_pos)),'r',label='+')
    plt.xlabel(label)
    plt.ylabel('Cumulative Probability')
    plt.ylim(0,1)
    plt.legend(loc=2)
Ejemplo n.º 5
0
def plot_roc_curve(Y,p_parks_tc,p_parks_r):
    fpr_tc,tpr_tc,roc_auc_tc = get_roc_curve(Y,p_parks_tc)
    fpr_r_mnb,tpr_r_mnb,roc_auc_r_mnb = get_roc_curve(Y,p_parks_r)
    plt.plot(fpr_tc, tpr_tc, lw=2, color='gray', label='AUC using Total Correct = %0.2f' % (roc_auc_tc))
    #plot(fpr_r_bnb, tpr_r_bnb, lw=2, color='r', label='Responses area = %0.2f' % (roc_auc_r_bnb))
    plt.plot(fpr_r_mnb, tpr_r_mnb, lw=2, color='g', label='AUC using individual responses = %0.2f' % (roc_auc_r_mnb))
    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.legend(loc="lower right")
Ejemplo n.º 6
0
def roc_showdown(p_x,p_y,o_x,o_y,x_diag,y_diag,title='AUC',color='black'):
    from sklearn.metrics import roc_curve,auc
    p = p_x - p_y
    o = o_x - o_y
    p = p[np.abs(o)==1] # Only cases where x or y equals 1, but not both.  
    o = o[np.abs(o)==1]
    o = o==1
    fpr,tpr,_ = roc_curve(o, p)
    plt.plot(fpr,1-tpr,label="%s = %.3f" % (title,auc(fpr,tpr)),c=color)
    x_diag = x_diag.replace('Clinpath ','').replace('Nos','NOS')
    y_diag = y_diag.replace('Clinpath ','').replace('Nos','NOS')
    plt.xlabel('False %s rate' % x_diag)#'Fraction %s misdiagnosed as %s' % (y_diag,x_diag))
    plt.ylabel('False %s rate' % y_diag)#'Fraction %s misdiagnosed as %s' % (x_diag,y_diag))
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
def plot_cumul_hist(data,booklet=None):
    """
    Plots cumulative histogram for PPMI data.
    data: output of load()
    booklet: optionally restrict to one of four booklets (1-4).  
    """
    
    if booklet:
        smell = [value['upsit'][booklet-1] for key,value in data.items()]
    else:
        smell = [sum(value['upsit']) for key,value in data.items()]
    recruitment = [value['recruitment'] for key,value in data.items()]
    
    smell_ctl = [smell[i] for i in range(len(recruitment)) if recruitment[i]==0]
    smell_ctl = sorted(smell_ctl)
    
    smell_pd = [smell[i] for i in range(len(recruitment)) if recruitment[i]==1]
    smell_pd = sorted(smell_pd)

    cumul_hist(smell_ctl,color='k')
    cumul_hist(smell_pd,color='r')

    plt.xlabel('UPSIT score')
    plt.ylabel('Cumulative Probability')