def test_map_k_too_big(targets, test_implicit_predicted_scores): user_ids = np.arange(test_implicit_predicted_scores.shape[0]) with pytest.raises(ValueError): mapk(targets=targets, user_ids=user_ids, preds=test_implicit_predicted_scores[user_ids, :], k=(targets.shape[1] + 1))
def test_map_1(targets, test_implicit_predicted_scores): user_ids = np.arange(test_implicit_predicted_scores.shape[0]) actual_score = mapk(targets=targets, user_ids=user_ids, preds=test_implicit_predicted_scores[user_ids, :], k=1) np.testing.assert_almost_equal(actual_score, 2 / 3)
def test_map(targets, test_implicit_predicted_scores): user_ids = np.array([1, 2]) actual_score = mapk(targets=targets, user_ids=user_ids, preds=test_implicit_predicted_scores[user_ids, :], k=4) assert actual_score == .75