Python에서 RocCurve 시각화하기.

2019. 5. 18. 15:23분석 Python/Visualization

 

딱히 함수로 지정되어있지 않은 것 같아서 공유합니다. + 저도 나중에 찾아서 보기 편하게 보려고요 ㅎㅎㅎ

 

def rocvis(true , prob , label ) :
    from sklearn.metrics import roc_curve
    if type(true[0]) == str :
        from sklearn.preprocessing import LabelEncoder
        le = LabelEncoder()
        true = le.fit_transform(true)
    else :
        pass
    fpr, tpr, thresholds = roc_curve(true, prob)
    plt.plot(fpr, tpr, marker='.', label = label  )
    
   
fig , ax = plt.subplots(figsize= (20,10))
plt.plot([0, 1], [0, 1], linestyle='--')
rocvis(test_y , Rf_prob[:,1] , "RandomFoest")
rocvis(test_y , GBM_prob[:,1] , "GBM")
rocvis(test_y , xgbprob[:,1] , "LightGBM")
rocvis(caty_Test , catprob[:,1] , "CatBoost")
plt.legend(fontsize = 18)
plt.title("Models Roc Curve" , fontsize= 25)
plt.show()

 

 

https://scikit-learn.org/stable/auto_examples/model_selection/plot_roc.html

 

Receiver Operating Characteristic (ROC) — scikit-learn 0.21.1 documentation

Note Click here to download the full example code Receiver Operating Characteristic (ROC) Example of Receiver Operating Characteristic (ROC) metric to evaluate classifier output quality. ROC curves typically feature true positive rate on the Y axis, and fa

scikit-learn.org

 

728x90