【发布时间】:2017-08-09 01:07:18
【问题描述】:
我正在做一个二元分类..我有一个不平衡的数据,我已经使用 svm 权重来试图缓解这种情况...... 如您所见,我已经计算并绘制了每个类的 roc 曲线,并且得到了以下图: 看起来这两个类最多一个..我不确定我是否做对了,因为这是我第一次绘制自己的 roc 曲线...我正在使用Scikit learn to plot ...单独绘制每个类是否正确..分类器是否未能对蓝色类进行分类?
这是我用来获取情节的代码:
y_pred = clf.predict_proba(X_test)[:,0] # for calculating the probability of the first class
y_pred2 = clf.predict_proba(X_test)[:,1] # for calculating the probability of the second class
fpr, tpr, thresholds = metrics.roc_curve(y_test, y_pred)
auc=metrics.auc(fpr, tpr)
print "auc for the first class",auc
fpr2, tpr2, thresholds2 = metrics.roc_curve(y_test, y_pred2)
auc2=metrics.auc(fpr2, tpr2)
print "auc for the second class",auc2
# ploting the roc curve
plt.plot(fpr,tpr)
plt.plot(fpr2,tpr2)
plt.xlim([0.0,1.0])
plt.ylim([0.0,1.0])
plt.title('Roc curve')
plt.xlabel('False positive rate')
plt.ylabel('True positive rate')
plt.legend(loc="lower right")
plt.show()
我知道有一种更好的方法可以写成字典,但我只是想先看看曲线
【问题讨论】:
-
你能展示一下你用来获取数据和绘图的代码吗?
-
当然我会更新我的问题
标签: python machine-learning scikit-learn