average precision
**Average Precision (AP)** is the **area under the precision-recall curve** — measuring ranking quality by averaging precision at each relevant result position, capturing both precision and recall in a single metric.
**What Is Average Precision?**
- **Definition**: Average of precision values at positions where relevant items appear.
- **Formula**: AP = (Σ P(k) × rel(k)) / (total relevant items).
- **Range**: 0 (worst) to 1 (perfect).
**How AP Works**
**1. Rank items by predicted relevance**.
**2. For each relevant item at position k, compute Precision@k**.
**3. Average these precision values**.
**Example**
Ranked list: R, N, R, R, N (R=relevant, N=not relevant).
- P@1 = 1/1 = 1.0 (1st relevant at position 1).
- P@3 = 2/3 = 0.67 (2nd relevant at position 3).
- P@4 = 3/4 = 0.75 (3rd relevant at position 4).
- AP = (1.0 + 0.67 + 0.75) / 3 = 0.81.
**Why Average Precision?**
- **Position-Aware**: Rewards relevant items at top positions.
- **Comprehensive**: Considers all relevant items, not just top-K.
- **Single Metric**: Combines precision and recall.
- **Ranking Quality**: Measures overall ranking effectiveness.
**AP vs. Other Metrics**
**vs. Precision@K**: AP considers all positions, P@K only top-K.
**vs. NDCG**: AP binary relevance, NDCG handles graded relevance.
**vs. MRR**: AP considers all relevant items, MRR only first.
**Applications**: Information retrieval, search evaluation, recommendation evaluation, object detection (mAP).
**Tools**: scikit-learn, IR evaluation libraries.
Average Precision is **comprehensive ranking evaluation** — by averaging precision at all relevant positions, AP captures both the quality and completeness of rankings in a single, interpretable metric.