Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hitrate #1159

Merged
merged 39 commits into from Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
04caa31
add movielens
Jul 28, 2020
e870498
Merge remote-tracking branch 'upstream/master'
Aug 5, 2020
28c5148
commit before merge
Sep 6, 2020
034b832
Merge remote-tracking branch 'upstream/master'
Oct 8, 2020
699e97d
First hitrate metric version
denyhoof Jul 16, 2020
ef3ce1e
Merge remote-tracking branch 'upstream/master'
Oct 18, 2020
9dae326
Merge remote-tracking branch 'upstream/master'
Mar 7, 2021
3c5e53a
Merge remote-tracking branch 'upstream/master'
zkid18 Mar 27, 2021
38abe3a
metrge with upstream
zkid18 Mar 27, 2021
2e7e891
fix topk_map
zkid18 Mar 27, 2021
1c89f51
fix error in map
zkid18 Mar 27, 2021
56a4186
tests for map
zkid18 Mar 27, 2021
3c7079a
top_k ndcg
zkid18 Mar 27, 2021
372e877
edit changelog
zkid18 Mar 27, 2021
c5f4435
edit the tabs
zkid18 Mar 28, 2021
2e1d957
check codestyle
zkid18 Mar 28, 2021
2402682
check the intent
zkid18 Mar 28, 2021
534d482
check the intent
zkid18 Mar 28, 2021
f3e927b
remove trailing whitespace
zkid18 Mar 28, 2021
c35a6a3
fixed hitrate
zkid18 Apr 4, 2021
e81e31f
fixed the docs
zkid18 Apr 4, 2021
2a60b31
hitrate
zkid18 Apr 4, 2021
9b6c04a
Merge remote-tracking branch 'upstream/master'
zkid18 Apr 4, 2021
560188e
Additive margin softmax (#1131)
Atharva-Phatak Mar 27, 2021
767b031
Readme update2 (#1142)
Scitator Mar 28, 2021
b1ad3e4
updated dl_cpu(workflows)- For passing CI-Tests (#1135)
Atharva-Phatak Mar 28, 2021
a5334fe
fix: `_key_value` for schedulers in case of multiple optimizers fixed…
bagxi Mar 28, 2021
c929ab5
Github CI fixes (#1143)
Scitator Mar 28, 2021
b40d166
Engine docs (#1141)
Scitator Mar 28, 2021
bd2c46b
v21.03.1
Scitator Mar 28, 2021
c0bc738
v21.03: minimal version fix (#1147)
Scitator Mar 29, 2021
5a15977
fix: nested dicts in loaders_params/samplers_params overriding (#1150)
bagxi Mar 31, 2021
fcbcfd1
docs (#1152)
elephantmipt Apr 1, 2021
cd96186
Github CI fix (#1148)
Scitator Apr 1, 2021
074534b
Niftireader (#1151)
ssktotoro Apr 2, 2021
e906e1e
Merge branch 'master' into fix_topk_metrics
zkid18 Apr 4, 2021
c8ba69b
add changelog
zkid18 Apr 4, 2021
630c621
solved runtime error
zkid18 Apr 5, 2021
e3a4d3c
hitrate calculation
zkid18 Apr 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- minimal requirements issue ([#1147](https://github.com/catalyst-team/catalyst/issues/1147))
- nested dicts in `loaders_params`/`samplers_params` overriding fixed ([#1150](https://github.com/catalyst-team/catalyst/pull/1150))
- fixed hitrate calculation issue ([#1155]) (https://github.com/catalyst-team/catalyst/issues/1155)

## [21.03.1] - 2021-03-28

Expand Down
8 changes: 6 additions & 2 deletions catalyst/metrics/functional/_hitrate.py
Expand Up @@ -7,7 +7,8 @@

def hitrate(outputs: torch.Tensor, targets: torch.Tensor, topk: List[int]) -> List[torch.Tensor]:
"""
Calculate the hit rate score given model outputs and targets.
Calculate the hit rate (aka recall) score given
model outputs and targets.
Hit-rate is a metric for evaluating ranking systems.
Generate top-N recommendations and if one of the recommendation is
actually what user has rated, you consider that a hit.
Expand Down Expand Up @@ -39,7 +40,10 @@ def hitrate(outputs: torch.Tensor, targets: torch.Tensor, topk: List[int]) -> Li
targets_sort_by_outputs = process_recsys_components(outputs, targets)
for k in topk:
k = min(outputs.size(1), k)
hits_score = torch.sum(targets_sort_by_outputs[:, :k], dim=1) / k
if targets.sum(dim=1).data[0] != 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is correct

hits_score = torch.sum(targets_sort_by_outputs[:, :k], dim=1) / targets.sum(dim=1)
else:
hits_score = torch.tensor([0.0])
results.append(torch.mean(hits_score))

return results
Expand Down
13 changes: 8 additions & 5 deletions catalyst/metrics/functional/tests/test_hitrate.py
Expand Up @@ -9,13 +9,16 @@ def test_hitrate():
"""
Tests for catalyst.metrics.hitrate metric.
"""
y_pred = [0.5, 0.2]
y_true = [1.0, 0.0]
k = [1, 2]
y_pred = [0.5, 0.2, 0.1]
y_true = [1.0, 0.0, 1.0]
k = [1, 2, 3]

hitrate_at1, hitrate_at2 = hitrate(torch.Tensor([y_pred]), torch.Tensor([y_true]), k)
assert hitrate_at1 == 1.0
hitrate_at1, hitrate_at2, hitrate_at3 = hitrate(
torch.Tensor([y_pred]), torch.Tensor([y_true]), k
)
assert hitrate_at1 == 0.5
assert hitrate_at2 == 0.5
assert hitrate_at3 == 1.0

# check 1 simple case
y_pred = [0.5, 0.2]
Expand Down