Exemplo n.º 1
0
def analysis():
    X, y = get_xy()    
    X_train, X_test, Y_train, Y_test, = \
                        train_test_split(X.toarray(), y, 
                                         test_size=0.3, random_state=42)
    clf = create_learner()
    clf.fit(X_train, Y_train)
    prob = clf.predict_proba(X_test)[:, 1]
    precision, recall, threld = precision_recall_curve(Y_test, prob)
    
    area = auc(recall, precision)
    plot_precision_recall(precision, recall, area, clf.__class__.__name__)
    ## roc
    fpr, tpr, roc_thresholds = roc_curve(Y_test, prob)
    area = auc(fpr, tpr)
    plot_roc(area, tpr, fpr, clf.__class__.__name__)
Exemplo n.º 2
0
def analysis():
    X, y = get_xy()
    X_train, X_test, Y_train, Y_test, = \
                        train_test_split(X.toarray(), y,
                                         test_size=0.3, random_state=42)
    clf = create_learner()
    clf.fit(X_train, Y_train)
    prob = clf.predict_proba(X_test)[:, 1]
    precision, recall, threld = precision_recall_curve(Y_test, prob)

    area = auc(recall, precision)
    plot_precision_recall(precision, recall, area, clf.__class__.__name__)
    ## roc
    fpr, tpr, roc_thresholds = roc_curve(Y_test, prob)
    area = auc(fpr, tpr)
    plot_roc(area, tpr, fpr, clf.__class__.__name__)
Exemplo n.º 3
0
def analysis_1vsN():
    print('============== One Vs Rest ==============')
    X_train, Y_train, X_test, Y_test, targetname = create_xy()
    clf = create_learner()
    clf.fit(X_train, Y_train)
    cm = confusion_matrix(Y_test, clf.predict(X_test))
    for i in range(3):
        print convert2d(cm, i)
        yy = np.asarray(Y_test==i, dtype=int)
        prob = clf.predict_proba(X_test)[:,i]
        ## precision-recall        
        precision, recall, threld = precision_recall_curve(yy, prob)
        area = auc(recall, precision)
        plot_precision_recall(precision, recall, area, targetname[i])
        ## roc
        fpr, tpr, roc_thresholds = roc_curve(yy, prob)
        area = auc(fpr, tpr)
        plot_roc(area, tpr, fpr, targetname[i])