Precision at K Calculator

Evaluate ranked recommendations at multiple K values, compare precision, recall, F1, hit rate, reciprocal rank, and export detailed machine learning results instantly with confidence.

Calculator Inputs

Choose one data format. Then enter ranked results and relevance data.

Enter one or several positive integers.
Use commas, spaces, semicolons, or new lines.
Format: query_id|predictions|relevant_items|weight
Format: query_id|binary_sequence|weight
Use an object, array, or a queries array.
Headers: query_id, predictions, relevant, weight.
Headers: query_id, binary, weight.

Formula Used

Precision@K = Relevant items among top K ÷ K

Precision@K measures relevance within the highest-ranked results. It focuses only on the selected cutoff. Higher values indicate more relevant top results.

Recall@K divides found relevant items by all relevant items. F1@K balances precision and recall together. Hit rate checks whether any relevant result appears.

Recall@K = relevant items found ÷ total relevant items
F1@K = 2 × precision × recall ÷ (precision + recall)

How to Use

  1. Choose item IDs or binary relevance values.
  2. Select a single, batch, JSON, or CSV source.
  3. Enter one or several positive K values.
  4. Choose duplicate and strict-K handling options.
  5. Press the calculation button.
  6. Review tables, charts, warnings, and comparison metrics.
  7. Copy, print, or download the results.

Worked Example

The ranked predictions are A, B, C, D, E, and F. Relevant items are A, C, D, and G. The selected cutoff is five.

RankItemRelevantCumulative precision
1AYes1.0000
2BNo0.5000
3CYes0.6667
4DYes0.7500
5ENo0.6000
Precision@5 = 3 ÷ 5 = 0.60 = 60%

Choosing K

Choose K using the visible result count. Search interfaces often show ten results. Recommendation panels may display fewer items.

Small K values test the strongest rankings. Larger K values test broader list quality. Compare several cutoffs before making decisions.

Applications and Limitations

Precision@K supports search, recommendation, retrieval, and ranking evaluation. It is simple and easy to explain. It also matches visible result lists.

The metric ignores result order within K. It can hide missed relevant items. Use recall, MAP, MRR, and nDCG alongside it.

Frequently Asked Questions

What does Precision@K measure?

It measures the relevant share among the top K predictions.

Can K exceed the prediction count?

Strict mode rejects that case. Available-results mode uses existing predictions.

How are duplicate predictions handled?

The calculator warns about duplicates. Unique mode removes repeated IDs.

What is macro Precision@K?

It averages query scores equally, regardless of query weight.

What is weighted Precision@K?

It gives larger weights more influence in the final average.

How does Precision@K differ from Recall@K?

Precision uses top-K results. Recall uses all known relevant items.

What is Hit Rate@K?

It equals one when any relevant result appears within K.

Why calculate MRR and nDCG?

They provide extra ranking sensitivity and early-result insight.

Can I evaluate multiple queries?

Yes. Use batch text, JSON, or a CSV file.

Related Calculators

User Similarity CalculatorItem Similarity CalculatorCollaborative Filtering CalculatorMean Reciprocal Rank CalculatorRecall at K CalculatorNormalised Discounted Cumulative Gain Calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.