Last active
October 26, 2022 22:57
-
-
Save jednano/920c92cc03be5021ee3d2a0a5895b67e to your computer and use it in GitHub Desktop.
Classification Metrics
This file contains 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
# TP = True Positive | |
# TN = True Negative | |
# FP = False Positive | |
# FN = False Negative | |
def precision(TP, FP): | |
return TP / (TP + FP) | |
def recall(TP, FN): | |
return TP / (TP + FN) | |
def negative_predictive_value(TN, FN): | |
return TN / (TN + FN) | |
def sensitivity(TP, FN): | |
return TP / (TP + FN) | |
def specificity(TN, FP): | |
return TN / (TN + FP) | |
def accuracy(TP, TN, FP, FN): | |
return (TP + TN) / (TP + TN + FP + FN) | |
def f1_score(TP, FP, FN): | |
P = precision(TP, FP) | |
R = recall(TP, FN) | |
return 2 * ((P * R) / (P + R)) | |
def f1_score_alt(TP, FP, FN): | |
return TP / (TP + ((FP + FN) / 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment