我计算了假阳性率和假阴性率。我正在使用这些技巧:
cnf_matrix=confusion_matrix(Ytest, y_pred)
print(cnf_matrix)
FP = cnf_matrix.sum(axis=0) - np.diag(cnf_matrix)
FN = cnf_matrix.sum(axis=1) - np.diag(cnf_matrix)
TP = np.diag(cnf_matrix)
TN = cnf_matrix.sum() - (FP + FN + TP)
FP = FP.astype(float)
print('FP: '+str(FP))
FN = FN.astype(float)
print('Fn: '+str(FN))
TP = TP.astype(float)
print('FN: '+str(FN))
TN = TN.astype(float)
print('TN: '+str(TN))
# false positive rate
FPR = FP/(FP+TN)
print('FPR: '+str(FPR))
# False negative rate
FNR = FN/(TP+FN)
print('FNR: '+str(FNR))
我得到了这些向量:
^{pr2}$但是,我只需要得到一个值,而不是一个向量。 怎么弄到的?在
对于多类分类,您的代码似乎是正确的。向量只是给出了这三个类的FPR和FNR。因为每个类的FPR和FNR不同。如果您只对一个类的FPR/FNR感兴趣,那么您可以通过给出索引来访问该分数
另一方面,对于二进制分类,我认为最好使用scikit learn的函数来计算这些值。在
FPR=1-TNR和TNR=特异性
FNR=1-TPR和TPR=recall
然后,可以计算FPR和FNR,如下所示:
^{pr2}$相关问题 更多 >
编程相关推荐