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

Assert error in BPR without user/item features #133

Closed
zzzrbx opened this issue Dec 16, 2016 · 3 comments
Closed

Assert error in BPR without user/item features #133

zzzrbx opened this issue Dec 16, 2016 · 3 comments

Comments

@zzzrbx
Copy link

zzzrbx commented Dec 16, 2016

I'm using precision_at_k from lightFM library with the code below.

    lightfm_model = LightFM(loss="bpr", no_components=25, random_state=0)

    lightfm_model.fit(interactions=coo_matrix((np.ones(len(training)), (training["user"], training["product"]))), num_threads=20)

    print lightfm_model.user_embeddings.shape 
    print lightfm_model.item_embeddings.shape

    print (precision_at_k(model=lightfm_model,
                              train_interactions=coo_matrix((np.ones(len(training)), (training["user"], training["product"]))),
                              test_interactions=coo_matrix((np.ones(len(test)), (test["user"], test["product"]))),
                              k=5,
                              user_features=None,
                              item_features=None) )

the size of user and item embeddings is correct (25 for both) but I'm getting:

assert self.user_embeddings.shape[0] >= user_features.shape[1]

AssertionError

Notice that I'm not using user/item features.

@maciejkula
Copy link
Collaborator

This assertion is meant to prevent you from passing interaction matrices of incompatible shapes into fit and predict. In this case, I think your test matrix has a larger first dimension than your train matrix, and so there are some users in the test set that were not in the original train set.

Can you check that this is not the case?

@zzzrbx
Copy link
Author

zzzrbx commented Dec 16, 2016 via email

@zzzrbx zzzrbx closed this as completed Dec 17, 2016
@maciejkula
Copy link
Collaborator

Arguably the library should be more informative about what's wrong. I'll look into providing a better error message.

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