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

ALS.Recommend function coo_matrix index access problem #27

Closed
msh-tf opened this issue May 8, 2017 · 2 comments
Closed

ALS.Recommend function coo_matrix index access problem #27

msh-tf opened this issue May 8, 2017 · 2 comments

Comments

@msh-tf
Copy link

msh-tf commented May 8, 2017

So the als.recommend function takes an 'int' for userid and a 'coo_matrix' for item_user_data.T which is a coo_matrix, however you cannot index coo_matrix that way so it fails for me

In [46]: ratings
Out[46]: 
<635810x14744082 sparse matrix of type '<class 'numpy.float64'>'
	with 115307196 stored elements in COOrdinate format>

In [47]: model.recommend(5, ratings.T)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-46-2d2962f49703> in <module>()
----> 1 model.recommend(5, ratings.T)

/Users/ml/lib/python3.5/site-packages/implicit/als.py in recommend(self, userid, user_items, N)
     87 
     88         # calcualte the top N items, removing the users own liked items from the results
---> 89         liked = set(user_items[userid].indices)
     90         count = N + len(liked)
     91         if count < len(scores):

TypeError: 'coo_matrix' object does not support indexing

If not a coo_matrix what should I pass to the recommend function?

@benfred
Copy link
Owner

benfred commented May 8, 2017

It should be a CSR matrix - I'll add some documentation this weekend to clear up, but something like 'model.recommend(5, ratings.T.tocsr())' should work.

@msh-tf
Copy link
Author

msh-tf commented May 8, 2017

Worked!
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants