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:
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:
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](https://github.com/practical-recommender-systems/moviegeek/assets/49819496/b3478e36-82f9-472a-96c5-3dbd1834a9f1)
Formula in the book: