Algorithm Search⌘K

Definitionintro

Precision at k

Also called P@k.

The fraction of the top k retrieved documents that are relevant.

Precision at k, written P@k, is the number of relevant documents among the first k documents of a ranking, divided by k. It is the precision of the set that a user sees when the user reads the first k results and stops. It needs only the judgments of the top k documents, so it is cheap to measure, but it ignores the order inside the top k and every document below rank k. It is the simplest metric of ranked retrieval on a test collection.

Definition

Input. A ranking d(1),d(2),…,d(n)d_{(1)}, d_{(2)}, \ldots, d_{(n)} of nn distinct document ids for a query qq, with rank ii starting at 1, and graded judgments: g(d)∈{0,1,2,…}g(d) \in \{0, 1, 2, \ldots\} for each document, with g(d)=0g(d) = 0 for a document that is not judged. A document is relevant when g(d)≥1g(d) \ge 1. Write reli=1\mathrm{rel}_i = 1 when d(i)d_{(i)} is relevant and reli=0\mathrm{rel}_i = 0 otherwise. RR is the number of relevant documents in the judgments.

Value. For an integer cutoff k≥1k \ge 1,

P@k=1k∑i=1min⁡(k,n)reli.\mathrm{P@}k = \frac{1}{k} \sum_{i=1}^{\min(k, n)} \mathrm{rel}_i .

The parts of the definition, in the order of the metric pages of this area:

  • Gain: binary. Grade 2 counts the same as grade 1. The threshold is a choice; trec_eval calls it the relevance level and sets it to 1 by default.
  • Discount: none. Each of the first kk ranks has weight 1/k1/k, and ranks after kk have weight 0.
  • Normalization: division by kk. It is not division by min⁡(k,n)\min(k, n) and not by min⁡(k,R)\min(k, R).
  • Fewer than kk results: the missing ranks count as nonrelevant, so the divisor stays kk. This is the trec_eval rule (file m_P.c). A run that returns 4 documents of which 2 are relevant has P@10 = 2/10.
  • Ties: the value depends on the order of documents with equal scores when a group of tied documents crosses rank kk. This area orders by score descending, then by document id ascending. trec_eval orders tied documents by document number in reverse lexical order (file form_res_rels.c), so the two rules can give different values from the same run file.
  • No relevant documents (R=0R = 0): P@k = 0 for every ranking. The value is defined, but it says nothing about the system, so a mean over queries usually leaves such a query out together with the queries that the other metrics cannot score.

Over a set of queries, mean P@k is the arithmetic mean of the values per query.

Bounds. 0≤P@k≤min⁡(k,R)/k0 \le \mathrm{P@}k \le \min(k, R)/k. The upper bound holds because at most RR of the first kk documents are relevant, and it is reached by every ranking that puts min⁡(k,R)\min(k, R) relevant documents first. So when R<kR < k, no system can reach P@k = 1. On a query with R=3R = 3, the best possible P@10 is 0.3.

Examples and non-examples

The fixed run on the toy collection

The shared toy collection of this area has 8 short documents. Query q1 is "sorted array search", with judgments d1 grade 2, d2 grade 1 and d8 grade 1, so R=3R = 3. The fixed run gives the scores d1 2.0, d6 2.0, d8 1.5, d2 1.0, d4 1.0. With the tie rule of this area the ranking is 1, 6, 8, 2, 4, and rel=1,0,1,1,0\mathrm{rel} = 1, 0, 1, 1, 0.

kk 1 2 3 4 5 10
relevant in top kk 1 1 2 3 3 3
P@k 1 1/2 2/3 3/4 3/5 3/10

P@1 = 1/1 = 1 and P@3 = 2/3. P@10 = 3/10, because the run returns only 5 documents and the divisor stays 10. P@k goes down from rank 1 to rank 2 and up again from rank 2 to rank 4. P@k is not monotone in kk, but k⋅P@kk \cdot \mathrm{P@}k, the count of relevant documents seen, never decreases.

The same run with the other tie rule

d1 and d6 both score 2.0, and d2 and d4 both score 1.0. trec_eval puts the larger document number first inside each tie, so it reads the run as 6, 1, 8, 4, 2 with rel=0,1,1,0,1\mathrm{rel} = 0, 1, 1, 0, 1. Then P@1 = 0, P@2 = 1/2, P@3 = 2/3, P@4 = 2/4 = 1/2 and P@5 = 3/5. P@1 moves from 1 to 0 with no change in the scores. P@3 and P@5 do not change, because no tie group crosses rank 3 or rank 5.

The tie-aware value of McSherry and Najork (2008) is the mean of P@k over all orders of the tied documents. For P@1 the two orders of {d1, d6} give 1 and 0, so the tie-aware P@1 is 1/2. For P@3 the value is 2/3 in every order. They show that this mean has a closed form: inside a tie group that crosses rank kk, each position counts the fraction of relevant documents in the group.

Query q4

q4 is "quantum circuit". No query term occurs in the collection and R=0R = 0. Every ranking has P@k = 0 for every kk.

Non-examples

  • Precision of a set, TP/(TP+FP)\mathrm{TP}/(\mathrm{TP} + \mathrm{FP}), as on precision and recall. It has no cutoff and no order. P@k is the precision of the set of the first kk ranks; it equals set precision only when the run returns exactly kk documents.
  • "Precision over the documents retrieved", that is, the count of relevant documents in the top kk divided by min⁡(k,n)\min(k, n). For the run above with k=10k = 10 it gives 3/5, not 3/10. It rewards a run for returning fewer documents. It is not P@k.
  • R-precision. It is precision at the cutoff k=Rk = R, which differs from query to query. P@k uses one fixed kk for all queries.
  • Recall at k, the count of relevant documents in the top kk divided by RR. For q1 at k=2k = 2 it is 1/3, while P@2 = 1/2.
  • Average precision is the mean of P@k over the ranks kk of the relevant documents, with 0 for each relevant document that is not retrieved. It is sensitive to the order inside the top kk, which P@k is not.
  • R-precision is P@R. At rank RR precision equals recall.
  • Success at k (also called hit rate at k) is 1 if the top kk holds at least one relevant document and 0 otherwise. Its mean over queries is close in spirit to mean reciprocal rank.
  • Normalized discounted cumulative gain uses the grades and a discount by rank, where P@k uses neither.
  • Rank-biased precision replaces the hard cutoff by a geometric weight on each rank.
  • The interpolated precision-recall curve uses the precision at every rank, not only at one cutoff.

Mean P@10 is a common report, but it is a noisy summary. Manning, Raghavan and Schuetze (Section 8.4) point out that it averages badly, because the number of relevant documents differs a lot from query to query, and a query with R=3R = 3 has a different scale from a query with R=300R = 300. Buckley and Voorhees (2004, Table 3) measured the agreement between system rankings by MAP and by P(10) on three TREC collections with full judgments. The Kendall tau values were 0.813, 0.729 and 0.721, lower than for R-precision (0.916, 0.851 and 0.899). These are measurements on those collections. To claim that one system has a higher mean P@k than another, use a paired test over the queries, such as the sign test, the Wilcoxon signed-rank test or a permutation test, and give the number of queries and the p-value.

References

  1. Christopher D. Manning, Prabhakar Raghavan and Hinrich Schuetze, Introduction to Information Retrieval, Cambridge University Press, 2008, Chapter 8, Section 8.4 (precision at k, and why it does not average well over queries)
  2. trec_eval, the TREC evaluation program by Chris Buckley, maintained by NIST, file m_P.c (P_k divides by k also when fewer than k documents are retrieved) and file form_res_rels.c (tied scores are ordered by document number in reverse lexical order)
  3. Frank McSherry and Marc Najork, Computing information retrieval performance measures efficiently in the presence of tied scores, ECIR 2008, LNCS 4956, pp. 414-421, tie-aware precision, equal to the mean over all orders of the tied documents
  4. Chris Buckley and Ellen M. Voorhees, Retrieval evaluation with incomplete information, SIGIR 2004, pp. 25-32, Section 3, Table 3 (Kendall tau between the system rankings by MAP and by P(10) on TREC-8, TREC-10 and TREC-12)
  5. Stefan Buettcher, Charles L. A. Clarke and Gordon V. Cormack, Information Retrieval, Implementing and Evaluating Search Engines, MIT Press, 2010, Chapter 12 (measuring effectiveness)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/6CDHT4/text.yaml