Skip to content

Instantly share code, notes, and snippets.

View sadimanna's full-sized avatar
🌏
Submitted Ph.D. thesis a few days ago

Siladittya Manna sadimanna

🌏
Submitted Ph.D. thesis a few days ago
View GitHub Profile
def specificity(y, pred, th=0.5):
tn = TN(y,pred,th)
fp = FP(y,pred,th)
return tn/(tn+fp)
def fscore(y,pred,beta=1.0):
p = precision(y,pred)
r = recall(y,pred)
return (1+beta**2)*p*r/((1+beta**2)*p+r)
def npv(y, pred, th=0.5):
tn = TN(y,pred,th)
fn = FN(y,pred,th)
return tn/(tn+fn)
def prevalence(y):
return np.sum(y)/y.shape[0]
def prevalence(y):
return np.sum(y)/y.shape[0]
def fdr(y,pred,th=0.5):
fp = FP(y,pred,th)
tp = TP(y,pred,th)
return fp/(fp+tp)
def for(y,pred,th=0.5):
fn = FN(y,pred,th)
tn = TN(y,pred,th)
return fn/(fn+tn)
def fnr(y,pred,th=0.5):
fn = FN(y,pred,th)
tp = TP(y,pred,th)
return fn/(tp+fn)
def fpr(y,pred,th=0.5):
fp = FP(y,pred,th)
tn = TN(y,pred,th)
return fp/(tn+fp)
def roc_curve(y,pred):
TPR = [0.0]
FPR = [0.0]
thresholds = np.arange(0.01,1.00+0.01,0.01)
for th in thresholds:
TPR.append(recall(y,pred,th))
FPR.append(fpr(y,pred,th))
return TPR,FPR,thresholds