Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

apk

Average Precision at k


Description

apk computes the average precision at k, in the context of information retrieval problems.

Usage

apk(k, actual, predicted)

Arguments

k

The number of elements of predicted to consider in the calculation.

actual

The ground truth vector of relevant documents. The vector can contain any numeric or character values, order does not matter, and the vector does not need to be the same length as predicted.

predicted

The predicted vector of retrieved documents. The vector can contain any numeric of character values. However, unlike actual, order does matter, with the most documents deemed most likely to be relevant at the beginning.

Details

apk loops over the first k values of predicted. For each value, if the value is contained within actual and has not been predicted before, we increment the number of sucesses by one and increment our score by the number of successes divided by k. Then, we return our final score divided by the number of relevant documents (i.e. the length of actual).

apk will return NaN if length(actual) equals 0.

See Also

Examples

actual <- c('a', 'b', 'd')
predicted <- c('b', 'c', 'a', 'e', 'f')
apk(3, actual, predicted)

Metrics

Evaluation Metrics for Machine Learning

v0.1.4
BSD_3_clause + file LICENSE
Authors
Ben Hamner [aut, cph], Michael Frasco [aut, cre], Erin LeDell [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.