I need specificity for my classification, which is defined as: TN/(TN+FP)
I am writing a custom counter function:
from sklearn.metrics import make_scorer def specificity_loss_func(ground_truth, predictions): print predictions tp, tn, fn, fp = 0.0,0.0,0.0,0.0 for l,m in enumerate(ground_truth): if m==predictions[l] and m==1: tp+=1 if m==predictions[l] and m==0: tn+=1 if m!=predictions[l] and m==1: fn+=1 if m!=predictions[l] and m==0: fp+=1 `return tn/(tn+fp) score = make_scorer(specificity_loss_func, greater_is_better=True)
Then
from sklearn.dummy import DummyClassifier clf_dummy = DummyClassifier(strategy='most_frequent', random_state=0) ground_truth = [0,0,1,0,1,1,1,0,0,1,0,0,1] p = [0,0,0,1,0,1,1,1,1,0,0,1,0] clf_dummy = clf_dummy.fit(ground_truth, p) score(clf_dummy, ground_truth, p)
When I run these commands, I get p like:
[0 0 0 0 0 0 0 0 0 0 0 0 0] 1.0
Why does my p change to a series of zeros when entering p = [0,0,0,1,0,1,1,1,1,0,0,1,0]