Last active
June 5, 2018 14:51
-
-
Save halfak/b925a2d45a3903a3e10dc5d6cd7c01b1 to your computer and use it in GitHub Desktop.
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 weighted_sum(score, weights): | |
return sum(weights[cls] * proba | |
for cls, proba in score['probability'].items()) | |
def normalized_weighted_sum(score, weights): | |
return weighted_sum(score, weights) / len(weights) | |
enwiki_weights = { | |
'Stub': 1, | |
'Start': 2, | |
'C': 3, | |
'B': 4, | |
'GA': 5, | |
'FA': 6 | |
} | |
normalized_weighted_sum( | |
{'probability': {'Stub': 0.5, | |
'Start': 0.3, | |
'C': 0.1, | |
'B': 0.05, | |
'GA': 0.05, | |
'FA': 0}}, | |
enwiki_weights) | |
0.308 * max(enwiki_weights.values()) |
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 weighted_sum(score, weights): | |
... return sum(weights[cls] * proba | |
... for cls, proba in score['probability'].items()) | |
... | |
>>> def normalized_weighted_sum(score, weights): | |
... return weighted_sum(score, weights) / len(weights) | |
... | |
>>> enwiki_weights = { | |
... 'Stub': 1, | |
... 'Start': 2, | |
... 'C': 3, | |
... 'B': 4, | |
... 'GA': 5, | |
... 'FA': 6 | |
... } | |
>>> | |
>>> normalized_weighted_sum( | |
... {'probability': {'Stub': 0.5, | |
... 'Start': 0.3, | |
... 'C': 0.1, | |
... 'B': 0.05, | |
... 'GA': 0.05, | |
... 'FA': 0}}, | |
... enwiki_weights) | |
0.30833333333333335 | |
>>> | |
>>> 0.308 * max(enwiki_weights.values()) | |
1.8479999999999999 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Chatting now, Aaron pointed out my mistake: this is a one-vs-rest classifier, unlike drafttopic. The sum of probabilities.