Skip to content
Snippets Groups Projects
Unverified Commit 3abfdaa2 authored by Quentin Haenn's avatar Quentin Haenn Committed by GitHub
Browse files

Fix scipy '.A' alias being deprecated (#631)


* Fix issue #628 with '.A' stuff on csr_matrix

* Modifying requirements.txt for numpy and another .A

---------

Co-authored-by: default avatartqtg <tuantq.vnu@gmail.com>
parent 27f4604b
No related branches found
No related tags found
No related merge requests found
...@@ -951,7 +951,7 @@ class TextModality(FeatureModality): ...@@ -951,7 +951,7 @@ class TextModality(FeatureModality):
if binary: if binary:
bow_mat.data.fill(1) bow_mat.data.fill(1)
return bow_mat if keep_sparse else bow_mat.A return bow_mat if keep_sparse else bow_mat.toarray()
def batch_tfidf(self, batch_ids, keep_sparse=False): def batch_tfidf(self, batch_ids, keep_sparse=False):
"""Return matrix of TF-IDF features corresponding to provided batch_ids """Return matrix of TF-IDF features corresponding to provided batch_ids
...@@ -972,7 +972,8 @@ class TextModality(FeatureModality): ...@@ -972,7 +972,8 @@ class TextModality(FeatureModality):
""" """
tfidf_mat = self.tfidf_matrix[batch_ids] tfidf_mat = self.tfidf_matrix[batch_ids]
return tfidf_mat if keep_sparse else tfidf_mat.A return tfidf_mat if keep_sparse else tfidf_mat.toarray()
class ReviewModality(TextModality): class ReviewModality(TextModality):
"""Review modality """Review modality
...@@ -1034,6 +1035,7 @@ class ReviewModality(TextModality): ...@@ -1034,6 +1035,7 @@ class ReviewModality(TextModality):
Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf). Apply sublinear tf scaling, i.e. replace tf with 1 + log(tf).
""" """
def __init__(self, def __init__(self,
data: List[tuple] = None, data: List[tuple] = None,
group_by: str = None, group_by: str = None,
......
...@@ -239,7 +239,7 @@ class UserKNN(Recommender): ...@@ -239,7 +239,7 @@ class UserKNN(Recommender):
if item_idx is not None: if item_idx is not None:
weighted_avg = compute_score_single( weighted_avg = compute_score_single(
True, True,
self.sim_mat[user_idx].A.ravel(), self.sim_mat[user_idx].toarray().ravel(),
self.iu_mat.indptr[item_idx], self.iu_mat.indptr[item_idx],
self.iu_mat.indptr[item_idx + 1], self.iu_mat.indptr[item_idx + 1],
self.iu_mat.indices, self.iu_mat.indices,
...@@ -251,7 +251,7 @@ class UserKNN(Recommender): ...@@ -251,7 +251,7 @@ class UserKNN(Recommender):
weighted_avg = np.zeros(self.num_items) weighted_avg = np.zeros(self.num_items)
compute_score( compute_score(
True, True,
self.sim_mat[user_idx].A.ravel(), self.sim_mat[user_idx].toarray().ravel(),
self.iu_mat.indptr, self.iu_mat.indptr,
self.iu_mat.indices, self.iu_mat.indices,
self.iu_mat.data, self.iu_mat.data,
...@@ -412,7 +412,7 @@ class ItemKNN(Recommender): ...@@ -412,7 +412,7 @@ class ItemKNN(Recommender):
if item_idx is not None: if item_idx is not None:
weighted_avg = compute_score_single( weighted_avg = compute_score_single(
False, False,
self.ui_mat[user_idx].A.ravel(), self.ui_mat[user_idx].toarray().ravel(),
self.sim_mat.indptr[item_idx], self.sim_mat.indptr[item_idx],
self.sim_mat.indptr[item_idx + 1], self.sim_mat.indptr[item_idx + 1],
self.sim_mat.indices, self.sim_mat.indices,
...@@ -424,7 +424,7 @@ class ItemKNN(Recommender): ...@@ -424,7 +424,7 @@ class ItemKNN(Recommender):
weighted_avg = np.zeros(self.num_items) weighted_avg = np.zeros(self.num_items)
compute_score( compute_score(
False, False,
self.ui_mat[user_idx].A.ravel(), self.ui_mat[user_idx].toarray().ravel(),
self.sim_mat.indptr, self.sim_mat.indptr,
self.sim_mat.indices, self.sim_mat.indices,
self.sim_mat.data, self.sim_mat.data,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment