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 bug in ALS explain when user_items contains negative confidence values. #313

Merged
merged 5 commits into from
Feb 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions implicit/als.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ def explain(self, userid, user_items, itemid, user_weights=None, N=10):

total_score = 0.0
h = []
for i, (itemid, confidence) in enumerate(nonzeros(user_items, userid)):
h_len = 0
for itemid, confidence in nonzeros(user_items, userid):
if confidence < 0:
continue

Expand All @@ -267,8 +268,9 @@ def explain(self, userid, user_items, itemid, user_weights=None, N=10):
score = weighted_item.dot(factor) * confidence
total_score += score
contribution = (score, itemid)
if i < N:
if h_len < N:
heapq.heappush(h, contribution)
h_len += 1
else:
heapq.heappushpop(h, contribution)

Expand Down