Skip to content

[BUG] SAR needs to be modified due to a breaking change in scipy #1954

@miguelgfierro

Description

@miguelgfierro

Description

With scipy 1.10.1, the item similarity matrix is a dense matrix

print(type(model.item_similarity))
print(type(model.user_affinity))
print(type(model.item_similarity) == np.ndarray)
print(type(model.item_similarity) == scipy.sparse._csr.csr_matrix)
print(model.item_similarity.shape)
print(model.item_similarity)

<class 'numpy.ndarray'>
<class 'scipy.sparse._csr.csr_matrix'>
True
False
(1646, 1646)
[[1.         0.10650888 0.03076923 ... 0.         0.         0.        ]
 [0.10650888 1.         0.15104167 ... 0.         0.00729927 0.00729927]
 [0.03076923 0.15104167 1.         ... 0.         0.         0.01190476]
 ...
 [0.         0.         0.         ... 1.         0.         0.        ]
 [0.         0.00729927 0.         ... 0.         1.         0.        ]
 [0.         0.00729927 0.01190476 ... 0.         0.         1.        ]]

but with scipy 1.11.1 the item similarity matrix is sparse

print(type(model.item_similarity))
print(type(model.user_affinity))
type(model.item_similarity) == np.ndarray
type(model.item_similarity) == scipy.sparse._csr.csr_matrix
print(model.item_similarity.shape)
<class 'numpy.ndarray'>
<class 'scipy.sparse._csr.csr_matrix'>
()

In which platform does it happen?

Related to #1951

How do we replicate the issue?

Expected behavior (i.e. solution)

Other Comments

We found that the issue was that during a division in Jaccard, scipy change the type. We talked to the authors of scipy and they told us that they did a breaking change in 1.11.0 scipy/scipy#18796 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions