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

Function to make top-k recommendations to all users in a fast way for ALS model. #179

Merged
merged 18 commits into from
Jun 20, 2019
Merged
Prev Previous commit
Next Next commit
PEP8ified
Tych0n committed Jun 14, 2019
commit 873943b1c9cc07b40b98c070e472fcf2d507ea59
14 changes: 7 additions & 7 deletions implicit/recommender_base.pyx
Original file line number Diff line number Diff line change
@@ -174,13 +174,13 @@ class MatrixFactorizationBase(RecommenderBase):
else:
best = sorted(enumerate(scores), key=lambda x: -x[1])
return list(itertools.islice((rec for rec in best if rec[0] not in liked), N))

@cython.boundscheck(False)
@cython.wraparound(False)
@cython.nonecheck(False)
def recommend_all(self, user_items, int N=10
, recalculate_user=False, filter_already_liked_items=False, filter_items=None
, int num_threads=0, show_progress=True, int batch_size=0):
def recommend_all(self, user_items, int N=10,
recalculate_user=False, filter_already_liked_items=False, filter_items=None,
int num_threads=0, show_progress=True, int batch_size=0):
"""
Recommends items for all users

@@ -211,17 +211,17 @@ class MatrixFactorizationBase(RecommenderBase):
show_progress : bool, optional
Whether to show a progress bar
batch_size : int, optional
To optimise memory usage while matrix multiplication, users are separated into groups
To optimise memory usage while matrix multiplication, users are separated into groups
and scored iteratively. By default batch_size == num_threads * 100

Returns
-------
numpy ndarray
Array of (number_users, N) with item's ids in reversed probability order
"""
if num_threads==0:
num_threads=multiprocessing.cpu_count()

if not isinstance(user_items, csr_matrix):
user_items = user_items.tocsr()