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

Add a recommend method for making customised recommendation for users? #5

Closed
vnnw opened this issue Aug 28, 2016 · 5 comments
Closed

Comments

@vnnw
Copy link

vnnw commented Aug 28, 2016

To compute similar artists is great, but making customised recommendation for each user based on his or her listening history could be better?

@benfred
Copy link
Owner

benfred commented Sep 8, 2016

I agree that adding something like this to the library makes a ton of sense. I'll see about adding this when I have some time.

In the meantime:

def predict(item_factors, user_factors, userid, N=10):
        scores = item_factors.dot(user_factors[userid])
        best = numpy.argpartition(scores, -N)[-N:]
        return sorted(zip(best, scores[best]), key=lambda x: -x[1])

should return the top N artists for userid.

@GuoleiSun
Copy link

Hi Benfred,
I think there is a problem in your code. You said cui is confidence matrix, whose elements should all be positive. And in this line:'' for i, confidence in nonzeros(Cui, u)'', you use cui as pu, which should be sparse.
And in your example, I think you didn't differentiate bm25_weight(plays) with confidence matrix because you simply use bm25_weight(plays) as confidence matrix.
Thanks for your code and achieved speed-up. But I don't think your implementation is the correct version of implicit feedback dataset in paper: http://yifanhu.net/PUB/cf.pdf

@benfred
Copy link
Owner

benfred commented Jan 7, 2017

I'm pretty sure that the code correctly implements the paper.

Pui is a binary value - its 1 if the user has interacted with an item and 0 otherwise. The Cui confidence matrix I'm passing in is a sparse matrix, with entries for only the positive preferences (Pui = 1). So iterating over the nonzeros of Cui means that Pui is 1 . If I listed it out explicitly the code would be:

        for i, confidence in nonzeros(Cui, u):
            factor = Y[i]
            A += (confidence - 1) * np.outer(factor, factor)
            Pui = 1
            b += confidence * factor * Pui

But since its just adding in a multiply by 1 - I don't need to do this. I made a note about this in the cython version: https://github.com/benfred/implicit/blob/master/implicit/_implicit.pyx#L89 but didn't bother in the python version

Also Cui can be set to any weighting scheme you want - it doesn't affect how the solution is derived (since its a constant wrt to the params we're minimizing). The original paper suggests using the log of the play counts.

@benfred
Copy link
Owner

benfred commented Feb 25, 2017

@vnnw the last commit refactors this to a class, with a recommend method for generating personalized recommendations: 8c18f16#diff-604d1b48a6ae71b2cc39b27249942f12R84

In addition to the snippet I posted above, this also filters out the users own liked items.

@benfred benfred closed this as completed Feb 25, 2017
@chapleau
Copy link

chapleau commented Apr 4, 2017

@benfred Just to make sure I get this right, when you say "Cui can be set to any weighting scheme you want", we're still assuming here that "empty" entries in the confidence matrix have a value set to exactly 1, right ?

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

No branches or pull requests

4 participants