Skip to content

add metric Specificity doesn't work #3351

@Emhyrr

Description

@Emhyrr
from pycaret.datasets import get_data
data = get_data('juice')

from pycaret.classification import *
s = setup(data, target = 'Purchase', session_id = 123, silent = True)

# create a custom function
def calculate_specificity(y, y_pred):
    
    tp, tn, fn, fp = 0.0,0.0,0.0,0.0
    for l,m in enumerate(y):        
        if m==y_pred[l] and m==1:
            tp+=1
        if m==y_pred[l] and m==0:
            tn+=1
        if m!=y_pred[l] and m==1:
            fn+=1
        if m!=y_pred[l] and m==0:
            fp+=1
            
    return tn/(tn+fp)

# add metric to PyCaret
add_metric('specificity', 'specificity', calculate_specificity)

lr = create_model('lr')

Originally posted by @moezali1 in #1593 (comment)

""""
But this doesn't work. It gives zero value
image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions