Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. def RatingHitRate(topNPredicted, leftOutPredictions):
  2. hits = defaultdict(float)
  3. total = defaultdict(float)
  4.  
  5. # For each left-out rating
  6. for userID, leftOutMovieID, actualRating, estimatedRating, _ in leftOutPredictions:
  7. # Is it in the predicted top N for this user?
  8. hit = False
  9. for movieID, predictedRating in topNPredicted[int(userID)]:
  10. if (int(leftOutMovieID) == movieID):
  11. hit = True
  12. break
  13. if (hit) :
  14. hits[actualRating] += 1
  15.  
  16. total[actualRating] += 1
  17.  
  18. # Compute overall precision
  19. for rating in sorted(hits.keys()):
  20. print (rating, hits[rating] / total[rating])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement