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()
반응형
'🐍 Python & library > Scikit-Learn' 카테고리의 다른 글
XGBoost GPU 로 가속하기 (0) | 2022.04.13 |
---|---|
[Scikit-Learn] 주요 Classifier와 Parameter 정리 (0) | 2021.09.24 |
[Scikit-learn] Logistic Regression 정리, 예제 (0) | 2021.04.04 |