Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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())
>>> 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
@adamwight

This comment has been minimized.

Copy link

commented Jun 4, 2018

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?

@adamwight

This comment has been minimized.

Copy link

commented Jun 5, 2018

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
You can’t perform that action at this time.