recpack icon indicating copy to clipboard operation
recpack copied to clipboard

Popularity recommender with less than K items

Open paraschakis opened this issue 3 years ago • 1 comments

A minor thing that could be an issue for smaller datasets.

Since the default value for K is 200 for popularity recommender, it will fail with a ValueError if the dataset has fewer than 200 items. This is because the dimensions of U, I, V will be different when creating a scr_matrix:

        U, I, V = [], [], []

        for user in users:
            U.extend([user] * self.K)
            I.extend(items)
            V.extend(values)

score_matrix = csr_matrix((V, (U, I)), shape=X.shape)

This of course can be solved by manually providing the value for K, but we can't rely on that.

Suggested fix: U.extend([user] * min(self.K, len(items)))

paraschakis avatar Feb 22 '23 15:02 paraschakis

Hi @paraschakis,

Thanks for reporting this bug! I'm adding it to the issue tracker for next release.

Lien

LienM avatar Feb 22 '23 15:02 LienM