🐍 Python & library/Scikit-Learn

[Scikit-Learn] Multiclass ROC Curve 그리기

복만 2021. 9. 28. 16:19

Scikit-learn의 sklean.metric.roc_curve 는 binary label에 대해서만 사용할 수 있다.

 

이를 이용해 Multiclass ROC Curve를 구하고 그리려면 각 class에 대해 ROC curve를 계산하고 각각 plotting해야 한다.

 

from sklearn.metrics import roc_curve
import matplotlib.pyplot as plt
for i in range(y.shape[-1]):
    fprs, tprs, _ = roc_curve(y[:,i], y_pred[:,i]) #calculate fprs and tprs for each class
    plt.plot(fprs,tprs,label='{}'.format(i)) #plot roc curve of each class
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.legend()

 

반응형