Skip to content

Instantly share code, notes, and snippets.

@halfak
Last active June 5, 2018 14:51
Show Gist options
  • Save halfak/b925a2d45a3903a3e10dc5d6cd7c01b1 to your computer and use it in GitHub Desktop.
Save halfak/b925a2d45a3903a3e10dc5d6cd7c01b1 to your computer and use it in GitHub Desktop.
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
Copy link

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