daily pastebin goal
45%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top