I need specificity
对于我的分类,其定义为:TN/(TN+FP)
我正在编写一个自定义记分器函数:
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)
当我运行这些命令时,我得到p
打印为:
[0 0 0 0 0 0 0 0 0 0 0 0 0]
1.0
为什么是我的p
当我输入时更改为一系列零p = [0,0,0,1,0,1,1,1,1,0,0,1,0]