For each retrieval query, rank items by descending score, compute Average Precision, then average the query scores to obtain mean Average Precision.
For one query:
AP=R1r=1∑nPrecision(r)rel(r)Across Q queries:
mAP=Q1q=1∑QAPqHere, r is a rank, R is the total number of relevant items in that query, and rel(r) is one when the item at rank r is relevant. If k is provided, only ranks through k contribute to the numerator, while R remains the total relevant count. A query with no relevant items has AP zero. Return map_value and ap_per_query in a dictionary.
Input: y_true_list = [[1, 0, 1, 0]], y_score_list = [[0.9, 0.8, 0.7, 0.1]], k = None
Output: {"map_value": 0.833333, "ap_per_query": [0.833333]}
Explanation: Relevant items occur at ranks 1 and 3, where precision is 1 and 2/3.
Input: y_true_list = [[1, 0, 1], [1, 1, 0]], y_score_list = [[0.9, 0.8, 0.7], [0.9, 0.8, 0.7]], k = None
Output: {"map_value": 0.916667, "ap_per_query": [0.833333, 1.0]}
Use np.argsort(-scores, kind="stable") to obtain each ranking.
Use cumulative relevant counts divided by np.arange(1, n + 1) for precision at every rank.
Mask the precision array by the ranked relevance labels before summing.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any
For each retrieval query, rank items by descending score, compute Average Precision, then average the query scores to obtain mean Average Precision.
For one query:
AP=R1r=1∑nPrecision(r)rel(r)Across Q queries:
mAP=Q1q=1∑QAPqHere, r is a rank, R is the total number of relevant items in that query, and rel(r) is one when the item at rank r is relevant. If k is provided, only ranks through k contribute to the numerator, while R remains the total relevant count. A query with no relevant items has AP zero. Return map_value and ap_per_query in a dictionary.
Input: y_true_list = [[1, 0, 1, 0]], y_score_list = [[0.9, 0.8, 0.7, 0.1]], k = None
Output: {"map_value": 0.833333, "ap_per_query": [0.833333]}
Explanation: Relevant items occur at ranks 1 and 3, where precision is 1 and 2/3.
Input: y_true_list = [[1, 0, 1], [1, 1, 0]], y_score_list = [[0.9, 0.8, 0.7], [0.9, 0.8, 0.7]], k = None
Output: {"map_value": 0.916667, "ap_per_query": [0.833333, 1.0]}
Use np.argsort(-scores, kind="stable") to obtain each ranking.
Use cumulative relevant counts divided by np.arange(1, n + 1) for precision at every rank.
Mask the precision array by the ranked relevance labels before summing.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any