Skip to content

Popularity recommender with less than K items #4

@paraschakis

Description

@paraschakis

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)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions