I need specificity
for my classification which is defined as :
TN/(TN+FP)
I am writing a custom scorer function :
from sklearn.
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)