Skip to content

Instantly share code, notes, and snippets.

@mannuscript
Created July 2, 2018 22:53
Show Gist options
  • Save mannuscript/1729acadb824168a5d2713d32cfda5bd to your computer and use it in GitHub Desktop.
Save mannuscript/1729acadb824168a5d2713d32cfda5bd to your computer and use it in GitHub Desktop.
def accuracy_multilabel(pred, ground_truth):
n = len(pred)
score = 0.0
for i in range(0,n):
d = {}
for label in pred[i]:
d[label] = 1
for label in ground_truth[i]:
if label in d:
d[label] = 2
else:
d[label] = 1
temp = 0
for ky in d.keys():
if d[ky] == 2:
temp = temp+1
score = score + float(temp)/len(d.keys())
return score/n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment