def MAP(self,rank): Map = MeanAveragePrecision() for elem in rank: Map.load(self.rating,elem) result=Map.computr() print "the MAP of ranking :" ,result return result
def test_RANK_MeanAveragePrecision(self): mavgp = MeanAveragePrecision() GT_DECISION = [1, 2, 4] TEST_DECISION = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] mavgp.load(GT_DECISION, TEST_DECISION) GT_DECISION = [1, 4, 8] mavgp.load(GT_DECISION, TEST_DECISION) GT_DECISION = [3, 5, 9, 25, 39, 44, 56, 71, 89, 123] TEST_DECISION = [ 123, 84, 56, 6, 8, 9, 511, 129, 187, 25, 38, 48, 250, 113, 3 ] mavgp.load(GT_DECISION, TEST_DECISION) assert_equal(mavgp.compute(), 0.707222)
def test_RANK_MeanAveragePrecision(self): mavgp = MeanAveragePrecision() GT_DECISION = [1, 2, 4] TEST_DECISION = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] mavgp.load(GT_DECISION, TEST_DECISION) GT_DECISION = [1, 4, 8] mavgp.load(GT_DECISION, TEST_DECISION) GT_DECISION = [3, 5, 9, 25, 39, 44, 56, 71, 89, 123] TEST_DECISION = [123, 84, 56, 6, 8, 9, 511, 129, 187, 25, 38, 48, 250, 113, 3] mavgp.load(GT_DECISION, TEST_DECISION) assert_equal(mavgp.compute(), 0.707222)
n = 100 step = 2 start = 10 (prec, recall, F1) = 0.0, 0.0, 0.0 count = 0 precision = [] recall = [] roc_auc = dict() total_recall = 0.0 total_mean_prec = 0.0 inner_count = 0 filename = "/home/dhiraj/projects/results/avg_precision_results_10-60.txt" mavgp = MeanAveragePrecision() with open(filename, "w") as myFile: while count < n: users = db.get_people_sorted_artists(start, step) for user in users: TEST_DECISION = [] GT_DECISION = [] s_matrix_vector = db.get_sparse_matrix_vector(str(user["_id"]).encode('utf-8')) if s_matrix_vector and len(s_matrix_vector[0]['array']) > 0: inner_count += 1 if inner_count < (step+1): v_vectors = functions.compute_v_vectors(s_matrix_vector[0]['col_index'])
step = 0 start = 119 (prec, recall, F1) = 0.0, 0.0, 0.0 count = 0 precision = [] recall = [] roc_auc = dict() total_recall = 0.0 total_prec = 0.0 total_f1 = 0.0 total_mean_prec = 0.0 inner_count = 0 filename = "/home/dhiraj/projects/results/dataset2/precision_results.txt" mavgp = MeanAveragePrecision() with open(filename, "w") as myFile: #while count < n: users = db.get_people_sorted_artists(start, step) for user in users: TEST_DECISION = [] GT_DECISION = [] s_matrix_vector = db.get_sparse_matrix_vector(str(user["_id"]).encode('utf-8')) if s_matrix_vector and len(s_matrix_vector[0]['array']) > 0: # inner_count += 1 # if inner_count < (step+1): v_vectors = functions.compute_v_vectors(s_matrix_vector[0]['col_index']) counts = dict() for vec in s_matrix_vector[0]['array']: