请找管理员授权。/funnyscript/edit_node_item.php
# -*- coding: utf-8 -*- import csv import copy import numpy as np import pandas as pd import sys import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt from sklearn import svm, datasets from sklearn.metrics import roc_curve, auc ###计算roc和auc #from sklearn import cross_validation y_score=[] y_test=[] file='' file2='' if len(sys.argv)>1: file=sys.argv[1] if len(sys.argv)>2: file2=sys.argv[2] with open(file,'r') as csvfile: reader = csv.reader(csvfile) y_score = [row[0] for row in reader] with open(file,'r') as csvfile: reader = csv.reader(csvfile) y_test = [row[1] for row in reader] print(len(y_test)) print(len(y_score)) print(y_test[0:100]) print(y_score[0:100]) y_test2=[] for a in y_test: y_test2.append(int(float(a))) y_score2=[] for a in y_score: y_score2.append(float(a)) print(len(y_test2)) print(len(y_score2)) print(y_test2[0:100]) print(y_score2[0:100]) #print(column1) # Compute ROC curve and ROC area for each class #y_test=np.array([0, 1, 0, 0, 1, 1, 1, 1, 1]) #y_score=np.array([ 0.63, 0.53, 0.36, 0.02, 0.70 ,1 , 0.48, 0.46, 0.57]) fpr,tpr,threshold = roc_curve(y_test2, y_score2) ###计算真正率和假正率 roc_auc = auc(fpr,tpr) ###计算auc的值 plt.figure() lw = 2 plt.figure(figsize=(10,10)) plt.plot(fpr, tpr, color='darkorange', lw=lw, label='ROC curve (area = %0.2f)' % roc_auc) ###假正率为横坐标,真正率为纵坐标做曲线 plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--') 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 example') plt.legend(loc="lower right") #plt.show() plt.savefig(file2,format='png')
ID=5712 draw_roc.py
保存
# -*- coding: utf-8 -*- import csv import copy import numpy as np import pandas as pd import sys import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt from sklearn import svm, datasets from sklearn.metrics import roc_curve, auc ###计算roc和auc #from sklearn import cross_validation y_score=[] y_test=[] file='' file2='' if len(sys.argv)>1: file=sys.argv[1] if len(sys.argv)>2: file2=sys.argv[2] with open(file,'r') as csvfile: reader = csv.reader(csvfile) y_score = [row[0] for row in reader] with open(file,'r') as csvfile: reader = csv.reader(csvfile) y_test = [row[1] for row in reader] print(len(y_test)) print(len(y_score)) print(y_test[0:100]) print(y_score[0:100]) y_test2=[] for a in y_test: y_test2.append(int(float(a))) y_score2=[] for a in y_score: y_score2.append(float(a)) print(len(y_test2)) print(len(y_score2)) print(y_test2[0:100]) print(y_score2[0:100]) #print(column1) # Compute ROC curve and ROC area for each class #y_test=np.array([0, 1, 0, 0, 1, 1, 1, 1, 1]) #y_score=np.array([ 0.63, 0.53, 0.36, 0.02, 0.70 ,1 , 0.48, 0.46, 0.57]) fpr,tpr,threshold = roc_curve(y_test2, y_score2) ###计算真正率和假正率 roc_auc = auc(fpr,tpr) ###计算auc的值 plt.figure() lw = 2 plt.figure(figsize=(10,10)) plt.plot(fpr, tpr, color='darkorange', lw=lw, label='ROC curve (area = %0.2f)' % roc_auc) ###假正率为横坐标,真正率为纵坐标做曲线 plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--') 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 example') plt.legend(loc="lower right") #plt.show() plt.savefig(file2,format='png')