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 |
Chatting now, Aaron pointed out my mistake: this is a one-vs-rest classifier, unlike drafttopic. The sum of probabilities.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have questions about this formula. Are the per-class probabilities guaranteed to sum to 1? That would be strange, since these predictions aren't mutually exclusive. If they don't sum to 1, then our normalization doesn't work as we expect, for example [0, 0, 0, 0, 1.0, 1.0] would sum to 11 and normalize to 11/6. Shouldn't the denominator be the sum of all weights?