What is Average Precision ?
Average precision is a metric used in information retrieval and data mining to evaluate the performance of a model in ranking items. It measures the average of the precision values at each position in the ranking, taking into account only the items that are relevant to the query.
For example, consider a search engine that receives a query for “jaguar car”. The engine returns a list of items, ranked in order of relevance to the query. The list may look like this:
Jaguar XE sedan
Jaguar XF sedan
Jaguar XJ sedan
Jaguar F-Type sports car
Jaguar XK sports car
Ford Mustang sports car
Toyota Camry sedan
Honda Civic sedan
In this case, the relevant items are the first four items in the list, as they are all jaguar cars. The precision at each position in the ranking is calculated as the number of relevant items up to that position, divided by the total number of items up to that position. For example, the precision at position 1 is 1/1=1.0, at position 2 is 2/2=1.0, at position 3 is 3/3=1.0, and at position 4 is 4/4=1.0.
The average precision is then calculated as the average of the precision values at each position in the ranking, taking into account only the relevant items. In this case, the average precision is (1.0+1.0+1.0+1.0)/4=1.0. This indicates that all relevant items are included in the top 4 positions of the ranking, and all of these items have a precision of 1.0.
In contrast, consider a different search engine that receives the same query for “jaguar car”. The engine returns a different list of items, ranked in order of relevance to the query. The list may look like this:
Ford Mustang sports car
Toyota Camry sedan
Honda Civic sedan
Jaguar XE sedan
Jaguar XF sedan
Jaguar XJ sedan
Jaguar F-Type sports car
Jaguar XK sports car
In this case, the relevant items are still the first four items in the list, as they are all jaguar cars. However, the precision at each position in the ranking is now calculated differently. For example, the precision at position 1 is 0/1=0.0, at position 2 is 0/2=0.0, at position 3 is 0/3=0.0, and at position 4 is 1/4=0.25.
The average precision is then calculated as the average of the precision values at each position in the ranking, taking into account only the relevant items. In this case, the average precision is (0.25+0.25+0.25+0.25)/4=0.25. This indicates that only 1 out of 4 relevant items are included in the top 4 positions of the ranking, and these items have a precision of 0.25.
Overall, average precision is a useful metric for evaluating the performance of a ranking model, as it takes into account both the relevance of the items and their position in the ranking. It is particularly useful in cases where the number of relevant items is small, as it allows the model to be evaluated based on the precision of these items rather than the overall recall of the ranking.