python matplotlib--畫多個roc曲線--備用


參考鏈接:

http://www.voidcn.com/article/p-ppgpswof-bvw.html

if __name__ == '__main__':
    from sklearn import metrics
    import numpy as np
    import matplotlib.pyplot as plt

    plt.figure(0).clf()  # plt.close()將完全關閉圖形窗口,其中plt.clf()將清除圖形-您仍然可以在其上繪制另一個繪圖。

    pred = np.random.rand(1000)
    label = np.random.randint(2, size=1000)
    fpr, tpr, thresh = metrics.roc_curve(label, pred)
    auc = metrics.roc_auc_score(label, pred)
    plt.plot(fpr, tpr, label="data 1, auc=" + str(auc))

    pred = np.random.rand(1000)
    label = np.random.randint(2, size=1000)
    fpr, tpr, thresh = metrics.roc_curve(label, pred)
    auc = metrics.roc_auc_score(label, pred)
    plt.plot(fpr, tpr, label="data 2, auc=" + str(auc))

    plt.legend(loc=0) # 說明所在位置
    plt.show()

 

 

結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM