benfred / implicit

Fast Python Collaborative Filtering for Implicit Feedback Datasets
https://benfred.github.io/implicit/
MIT License
3.57k stars 612 forks source link

IndexError in rank items #574

Closed avichai-edri closed 2 years ago

avichai-edri commented 2 years ago

hii. im trign to get the rank of item for user and i get Index Error

sparse_item_user = sparse.csr_matrix((clicks, (targets, users))) sparse_user_item = sparse.csr_matrix((clicks, (users, targets)))

als_model = implicit.als.AlternatingLeastSquares(factors=60, num_threads =1) alpha_val = 40 data_conf = (sparse_item_user * alpha_val).astype('double') als_model.fit(data_conf )

als_model.rank_items(1405380,sparse_user_item,[72069]) its raise: index 1405380 is out of bounds for axis 0 with size 138101

how can i solve it?

benfred commented 2 years ago

model.fit takes a user_items matrix - and it looks like you are passing it a item_users matrix (this is a breaking API change as of implicit v0.5.0). Can you try fitting the model with

 data_conf = (sparse_user_item * alpha_val).astype('float32')
als_model.fit(data_conf )

instead?

benfred commented 2 years ago

closing this - @avichai-edri feel free to re-open if this is still an issue