Skip to content

Instantly share code, notes, and snippets.

@SrivastavaKshitij
Created September 3, 2018 21:34
Show Gist options
  • Save SrivastavaKshitij/ac7eae43adb7a5da6e7d5269660d984b to your computer and use it in GitHub Desktop.
Save SrivastavaKshitij/ac7eae43adb7a5da6e7d5269660d984b to your computer and use it in GitHub Desktop.
Performance metric
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