參考鏈接:
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()
結果: