2017-03-20 1 views
2

건물 2 개 모델입니다.파이썬에서 범례 및 AUC 점수를 사용하여 한 줄에 여러 ROC 곡선을 그립시키는 방법은 무엇입니까?

모델 1

modelgb = GradientBoostingClassifier() 
modelgb.fit(x_train,y_train) 
predsgb = modelgb.predict_proba(x_test)[:,1] 
metrics.roc_auc_score(y_test,predsgb, average='macro', sample_weight=None) 

모델 2

model = LogisticRegression() 
model = model.fit(x_train,y_train) 
predslog = model.predict_proba(x_test)[:,1] 
metrics.roc_auc_score(y_test,predslog, average='macro', sample_weight=None) 

어떻게 각 모델에 대한 AUC 점수의 전설 & 텍스트로, 하나의 플롯의 ROC 곡선 모두 음모합니까? 데이터에이 적응

+0

사용하는 라이브러리? – Julien

+0

내가 matplotlib를 가지고 있지만 무엇이든 제안 할 수 있습니다 - 관련 라이브러리를 가져올 수 있습니다. – Pb89

+0

모델을 묻습니다 ... – Julien

답변

2

시도 :

from sklearn import metrics 
import numpy as np 
import matplotlib.pyplot as plt 

plt.figure(0).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) 
관련 문제