This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def specificity(y, pred, th=0.5): | |
| tn = TN(y,pred,th) | |
| fp = FP(y,pred,th) | |
| return tn/(tn+fp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def npv(y, pred, th=0.5): | |
| tn = TN(y,pred,th) | |
| fn = FN(y,pred,th) | |
| return tn/(tn+fn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def prevalence(y): | |
| return np.sum(y)/y.shape[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def prevalence(y): | |
| return np.sum(y)/y.shape[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fdr(y,pred,th=0.5): | |
| fp = FP(y,pred,th) | |
| tp = TP(y,pred,th) | |
| return fp/(fp+tp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def for(y,pred,th=0.5): | |
| fn = FN(y,pred,th) | |
| tn = TN(y,pred,th) | |
| return fn/(fn+tn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fnr(y,pred,th=0.5): | |
| fn = FN(y,pred,th) | |
| tp = TP(y,pred,th) | |
| return fn/(tp+fn) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fpr(y,pred,th=0.5): | |
| fp = FP(y,pred,th) | |
| tn = TN(y,pred,th) | |
| return fp/(tn+fp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |