[BUG] Attribute Error with csr_matrix using Recommender based models
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.
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.
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 !