For a set of retrieval queries, compute Average Precision (AP) per query and Mean Average Precision (mAP) across all queries. Each query has items with binary relevance labels and real-valued scores.
Mean Average Precision is a standard evaluation metric in information retrieval and object detection. It measures the quality of ranked retrieval results by considering both precision and the ranking order of relevant items.
mAP Formulation:
Average Precision for a single query:
AP=R1k=1∑nP(k)rel(k)Mean Average Precision across queries:
mAP=Q1q=1∑QAPqWhere P(k) is precision at rank k, rel(k) is relevance at rank k, R is total relevant items, and Q is number of queries.
y_true_list: list of arrays - Binary relevance labels {0,1} for each queryy_score_list: list of arrays - Real-valued scores for each query (same lengths)k: optional int - Cutoff rank; if None, use full lengthInput: y_true_list = [[1, 0, 1, 0]], y_score_list = [[0.9, 0.8, 0.7, 0.1]]
Output: (0.8333, [0.8333])
Sorted by score: labels become [1, 0, 1, 0]. P(1)=1.0, P(3)=2/3. AP = (1.0 + 0.667)/2 = 0.8333
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]]
Output: (0.9167, [0.8333, 1.0])
Query 1: AP = 0.8333. Query 2: both relevant items at top, AP = 1.0. mAP = (0.8333 + 1.0)/2 = 0.9167
Sort indices by descending score using np.argsort() for each query.
Use np.cumsum() to get cumulative relevant items and compute precision at each rank.
Average precision is the mean of precisions at positions where items are relevant.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any
For a set of retrieval queries, compute Average Precision (AP) per query and Mean Average Precision (mAP) across all queries. Each query has items with binary relevance labels and real-valued scores.
Mean Average Precision is a standard evaluation metric in information retrieval and object detection. It measures the quality of ranked retrieval results by considering both precision and the ranking order of relevant items.
mAP Formulation:
Average Precision for a single query:
AP=R1k=1∑nP(k)rel(k)Mean Average Precision across queries:
mAP=Q1q=1∑QAPqWhere P(k) is precision at rank k, rel(k) is relevance at rank k, R is total relevant items, and Q is number of queries.
y_true_list: list of arrays - Binary relevance labels {0,1} for each queryy_score_list: list of arrays - Real-valued scores for each query (same lengths)k: optional int - Cutoff rank; if None, use full lengthInput: y_true_list = [[1, 0, 1, 0]], y_score_list = [[0.9, 0.8, 0.7, 0.1]]
Output: (0.8333, [0.8333])
Sorted by score: labels become [1, 0, 1, 0]. P(1)=1.0, P(3)=2/3. AP = (1.0 + 0.667)/2 = 0.8333
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]]
Output: (0.9167, [0.8333, 1.0])
Query 1: AP = 0.8333. Query 2: both relevant items at top, AP = 1.0. mAP = (0.8333 + 1.0)/2 = 0.9167
Sort indices by descending score using np.argsort() for each query.
Use np.cumsum() to get cumulative relevant items and compute precision at each rank.
Average precision is the mean of precisions at positions where items are relevant.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: any