Specificity in scikit learn

后端 未结 4 1145
遇见更好的自我
遇见更好的自我 2021-02-04 05:19

I need specificity for my classification which is defined as : TN/(TN+FP)

I am writing a custom scorer function :

from sklearn.         


        
4条回答
  •  不知归路
    2021-02-04 05:49

    You could get specificity from the confusion matrix. For a binary classification problem, it would be something like:

    from sklearn.metrics import confusion_matrix
    y_true = [0, 0, 0, 1, 1, 1, 1, 1]
    y_pred = [0, 1, 0, 1, 0, 1, 0, 1]
    tn, fp, fn, tp = confusion_matrix(y_true, y_pred).ravel()
    specificity = tn / (tn+fp)
    

提交回复
热议问题