Created
July 2, 2018 22:53
-
-
Save mannuscript/1729acadb824168a5d2713d32cfda5bd to your computer and use it in GitHub Desktop.
Multilabel accuracy based on: https://stats.stackexchange.com/questions/12702/what-are-the-measure-for-accuracy-of-multilabel-data#answer-168952
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
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