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

[BUG] Attribute Error with csr_matrix using Recommender based models #629

Open
quentinhaenn opened this issue Jun 25, 2024 · 2 comments · May be fixed by #631
Open

[BUG] Attribute Error with csr_matrix using Recommender based models #629

quentinhaenn opened this issue Jun 25, 2024 · 2 comments · May be fixed by #631

Comments

@quentinhaenn
Copy link

Description

Using any of the model based on Recommender abstract class causes an Attribute Error Exception: csr_matrix object has no attribute A.

Tested with ItemKNN and UserKnn so far. SVD model works well with same dataset.

In which platform does it happen?

MacOS 14.5 with arm platform (M1)
Python3.12

How do we replicate the issue?

MWE:

from cornac.data import Reader, Dataset
from cornac.eval_methods import StratifiedSplit
from cornac.models import ItemKNN, UserKNN, SVD
from cornac.datasets import movielens
data = movielens.load_feedback(variant="1M")
dataset= Dataset.from_uir(data)
split= StratifiedSplit(data, test_size=0.2, seed=42, rating_threshold=4)
train_data=split.train_set
test_set=split.test_set

item_knn = ItemKNN(k=10)
item_knn.fit(train_data)

user_knn = UserKNN(k=10)
user_knn.fit(train_data)

svd = SVD()
svd.fit(train_data)

item_knn.recommend(user_id='42', k=5) <--- issue from car_matrix
user_knn.recommend(user_id='42', k=5) <--- same
svd.recommend(user_id='42', k=5) <----- no issue here

Issue traceback seems to indicate an issue in the source code, where ui_mat is defined with csr_matrix, and using ui_mat.A.ravel() in file cornac/models/knn/recom_knn.py

Expected behavior (i.e. solution)

Expect the models to recommend as the SVD does, without throwing any internal error.

@tqtg
Copy link
Member

tqtg commented Jun 26, 2024

Is it possible to specify Numpy and Scipy version causing the error?

Updated: it seems that .A alias has been deprecated since Scipy 1.11.0 based on the release note. We might need to update our model implementation.

@quentinhaenn
Copy link
Author

Thanks for the reply.

I currently run with Numpy 1.26 and Scipy 1.14. Since you pointed out that .A as been deprecated since Scipy 1.11 this might be the issue.

I'll take a look at it.
Thanks again !

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

Successfully merging a pull request may close this issue.

2 participants