if len(games) < i + 1: games.append([]) user_id = d[0] dct[d[1]] = d[4] if d[4] == "1": games[i].append(d[1]) # Correctly recommended games / all recommended games avg_prec = 0.0 # Correctly recommended games / all games that should have been recommended avg_recall = 0.0 j = 0 for i in range(len(games) - 1): if len(games[i]) < 2: continue r = Recommend("Frequent_Itemsets.txt") r.set_user_games(games[i]) recommended = r.recommend() # Caluclate Precision and recall. all_rec = len(recommended) should_rec = 0 correct = 0 for key in final_dict[i]: game = key.split('"')[1] if final_dict[i][key] == "0": should_rec += 1 if game in recommended: correct += 1 if should_rec == 0 or all_rec == 0: continue prec = float(float(correct) / float(all_rec)) recall = float(float(correct) / float(should_rec))