Created
September 3, 2018 21:34
-
-
Save SrivastavaKshitij/ac7eae43adb7a5da6e7d5269660d984b to your computer and use it in GitHub Desktop.
Performance metric
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
import numpy as np | |
def pf(output,target,metric=None): | |
TP = np.count_nonzero(data*target) | |
TN = np.count_nonzero((data - 1) * (target - 1)) | |
FP = np.count_nonzero(data * (target - 1)) | |
FN = np.count_nonzero((data - 1) * target) | |
precision = TP / (TP + FP) | |
recall = TP / (TP + FN) | |
F1 = 2 * precision * recall / (precision + recall) | |
accuracy = (TP+TN)/(TP+TN+FP+FN) | |
PPV = TP/(TP+FP) | |
if metric=='precision': | |
return precision | |
elif metric=='recall': | |
return recall | |
elif metric=='PPV': | |
return PPV | |
elif metric=='accuracy': | |
return accuracy | |
else: return F1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment