二分类的话
import numpy as np
from sklearn.metrics import roc_curve, auc
y = np.array([1, 1, 1, 1, 1,
2, 2, 2, 2, 2])
y_proba = np.array([0.1, 0.4, 0.4, 0.3, 0.5,
0.4, 0.6, 0.7, 0.8, 0.5]) # probability of prediction as positive
fpr, tpr, thresholds = roc_curve(y, y_proba, pos_label=2)
auc = auc(fpr, tpr)
如上所示,roc_curve
里面应该为标签和概率,标签非独热码
计算AUC
>>> import numpy as np
>>> from sklearn.metrics import roc_auc_score
>>> y_true = np.array([0, 0, 1, 1])
>>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])
>>> roc_auc_score(y_true, y_scores)
0.75