Skip to content

Instantly share code, notes, and snippets.

@flaviovdf
Created February 8, 2018 19:15
Show Gist options
  • Save flaviovdf/3d085f8fe4a9951698925e786b89629a to your computer and use it in GitHub Desktop.
Save flaviovdf/3d085f8fe4a9951698925e786b89629a to your computer and use it in GitHub Desktop.
def precision10(A_true, A_pred, k=10):
res = 0.0
tmp = 0
for i in range(A_true.shape[0]):
x = set(A_true[i].argsort()[::-1][:k])
y = set(A_pred[i].argsort()[::-1][:k])
res += len(x.intersection(y)) / len(x)
tmp += 1
return res / tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment