Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def RatingHitRate(topNPredicted, leftOutPredictions):
- hits = defaultdict(float)
- total = defaultdict(float)
- # For each left-out rating
- for userID, leftOutMovieID, actualRating, estimatedRating, _ in leftOutPredictions:
- # Is it in the predicted top N for this user?
- hit = False
- for movieID, predictedRating in topNPredicted[int(userID)]:
- if (int(leftOutMovieID) == movieID):
- hit = True
- break
- if (hit) :
- hits[actualRating] += 1
- total[actualRating] += 1
- # Compute overall precision
- for rating in sorted(hits.keys()):
- print (rating, hits[rating] / total[rating])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement