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

Inferences' issue #153

Open
quannm3110 opened this issue Nov 13, 2019 · 1 comment
Open

Inferences' issue #153

quannm3110 opened this issue Nov 13, 2019 · 1 comment

Comments

@quannm3110
Copy link

Hi,

Is there anyone knowing how to run prediction in batch? I got run-out-of-memory problem since my data is way too big (5 million users x 5.000 items).

Thanks in advance.

@quannm3110
Copy link
Author

I found the way to work around with it.

from scipy.sparse import csr_matrix     

# Prediction in batch
batch_size = 1000
start_batch = 0
while start_batch < n_users:

    # min() ensures that the batch bounds doesn't go past the end of the index
    end_batch = min(start_batch + batch_size, n_users)
    prediction_batched = cf_model.predict(
          csr_matrix(users_features)[start_batch:end_batch], 
          items_features)
    start_batch = end_batch

If you want to predict a single user towards a single item, you can use the following script.

 cf_model.predict(
      csr_matrix(user_features)[325403], 
      csr_matrix(item_features)[838]
 )

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

1 participant