ROC curve for binary classification in python

前端 未结 1 1315
半阙折子戏
半阙折子戏 2020-12-30 11:11

I am tying to plot an ROC curve for Binary classification using RandomForestClassifier

I have two numpy arrays one contains predicted values and one co

相关标签:
1条回答
  • 2020-12-30 11:42

    You need probabilities to create ROC curve.

    In [84]: test
    Out[84]: array([0, 1, 0, ..., 0, 1, 0])
    
    In [85]: pred
    Out[85]: array([0.1, 1, 0.3, ..., 0.6, 0.85, 0.2])
    

    Example code from scikit-learn examples:

    import matplotlib.pyplot as plt
    from sklearn.metrics import roc_curve, auc
    fpr = dict()
    tpr = dict()
    roc_auc = dict()
    for i in range(2):
        fpr[i], tpr[i], _ = roc_curve(test, pred)
        roc_auc[i] = auc(fpr[i], tpr[i])
    
    print roc_auc_score(test, pred)
    plt.figure()
    plt.plot(fpr[1], tpr[1])
    plt.xlim([0.0, 1.0])
    plt.ylim([0.0, 1.05])
    plt.xlabel('False Positive Rate')
    plt.ylabel('True Positive Rate')
    plt.title('Receiver operating characteristic')
    plt.show()
    
    0 讨论(0)
提交回复
热议问题