Created
October 19, 2016 13:13
-
-
Save mlopatka/de804ad9662f408f411b365ffcab0e7e to your computer and use it in GitHub Desktop.
Cumalitive Gain for addons
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 vcg(r, t): | |
# r = list of recomendeed addons | |
# t = list of gold standard addons from user | |
# vanilla cumulative gain | |
r = list(set(filter(bool, r))) # sometimes this needs cleaning due to text formatting issues | |
t = list(set(filter(bool, t))) | |
r_dict = dict(zip(r, [0.0] * len(r))) | |
t_dict = dict(zip(t, [1.0 / len(t)] * len(t))) # weights independent of number of groung truth addons | |
full_dict = dict(r_dict.items() + t_dict.items()) | |
# order is important, ground truth keys in second position overwrite values (0.0) from reccomeded keys in the dict | |
return sum([full_dict[x] for x in r]) # score independent of order | |
# test cases: | |
gold_standard_addons = [u'Session Manager', u'ZenMate Security & Privacy VPN', u'Ghostery', u'Hoxx VPN Proxy', u'DoNotTrackMe', u'Adblock Plus', u'Google Reverse Image Search'] | |
recomended_addons = [u'Outlook Notifier', u'Gmail\u2122 Notifier +', u'Black Youtube Theme', u'SQLite Manager', u'DownThemAll!', u'IE View', u'Open in IE\u2122 (Internet Explorer)', u'Quick Preference Button', u'Ghostery'] | |
print vcg(gold_standard_addons,recomended_addons) | |
print vcg(gold_standard_addons,recomended_addons) | |
print vcg(recomended_addons, gold_standard_addons) | |
print vcg(gold_standard_addons, gold_standard_addons) | |
print vcg(recomended_addons, recomended_addons) | |
print vcg(recomended_addons[1::4], recomended_addons) | |
print vcg(recomended_addons, recomended_addons[1::4]) | |
print vcg([1,2,3], [1,2,3,4,5,6,7,8,9]) | |
print vcg([1],[1,2]) | |
print vcg([1,2],[1]) | |
print vcg([1,2,3,4,5,6,7],[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment