Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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