我有来自 SVM 的分数。我自己没有运行 SVM 模型而是下载了 SVM 原始分数。我知道 SVM 分数不给出概率,而是给出负值和正值。正值属于一类,负值属于另一类。我想为这些分数绘制 ROC 曲线。考虑到我没有 SVM 模型本身,只有分数,我该怎么做。
我有每个数据点的真实标签。我尝试将这些与原始分数一起使用,如下所示:
true_label = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Svm_score = [5.541873000000001, 5.541873000000001, 3.34974, 3.34974, 3.34974, 4.2332410000000005, 4.2332410000000005, 4.2332410000000005, 4.504345, 4.504345,0.41775200000000007, 1.139519, 0.241608, 0.241608, 0.241608, -1.458294, -1.458294, 0.898201, -0.575108, 0.442248]
###Plotting
fpr,tpr,threshold = roc_curve(true_label, svm_score)
print(threshold)
roc_auc = auc(fpr,tpr) ###Calculate the value of auc, auc is the area surrounded by the curve, the bigger the better
plt.figure()
lw = 2
plt.figure(figsize=(10,10))
plt.plot(fpr, tpr, color='darkorange',
lw=lw, label='ROC curve (area = %0.2f)'% roc_auc) ###The false positive rate is the abscissa, the true rate is the ordinate to make the curve
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic example')
plt.legend(loc="lower right")
plt.show()
但是,我得到以下图表,但没有任何意义: