Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User mean is cancelled out in recommenders #73

Open
ksiar137 opened this issue Mar 10, 2024 · 0 comments
Open

User mean is cancelled out in recommenders #73

ksiar137 opened this issue Mar 10, 2024 · 0 comments

Comments

@ksiar137
Copy link

When you calculate the predictions for in the recommenders, the user mean is calculated, but then substracted from each rating, resulting in it being canceled out.
Example:

    **user_mean** = sum(movie_ids.values()) / len(movie_ids)

    candidate_items = Similarity.objects.filter(Q(source__in=movie_ids.keys())
                                                & ~Q(target__in=movie_ids.keys())
                                                & Q(similarity__gt=self.min_sim)
                                                )
    candidate_items = candidate_items.order_by('-similarity')[:self.max_candidates]


    recs = dict()
    for candidate in candidate_items:
        target = candidate.target

        pre = 0
        sim_sum = 0

        rated_items = [i for i in candidate_items if i.target == target][:self.neighborhood_size]

        if len(rated_items) > 1:
            for sim_item in rated_items:
                r = Decimal(movie_ids[sim_item.source] - **user_mean**)
                pre += sim_item.similarity * r
                sim_sum += sim_item.similarity
            if sim_sum > 0:
                recs[target] = {'prediction': Decimal(**user_mean**) + pre / sim_sum,
                                'sim_items': [r.source for r in rated_items]}

I illustrated what is happening with equations. You can see that the user mean is cancelled out and the result we get is not the same formula as the one in the book:
image

Formula in the book:

image

@ksiar137 ksiar137 changed the title User mean is cancelled out in reccomenders User mean is cancelled out in recomenders Mar 10, 2024
@ksiar137 ksiar137 changed the title User mean is cancelled out in recomenders User mean is cancelled out in recommenders Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant