metrics {rsparse} | R Documentation |
Ranking Metrics for Top-K Items
Description
ap_k
calculates Average Precision at K (ap@k
).
Please refer to Information retrieval wikipedia article
ndcg_k()
calculates Normalized Discounted Cumulative Gain at K (ndcg@k
).
Please refer to Discounted cumulative gain
Usage
ap_k(predictions, actual, ...)
ndcg_k(predictions, actual, ...)
Arguments
predictions |
matrix of predictions. Predctions can be defined 2 ways:
|
actual |
sparse Matrix of relevant items. Each non-zero entry considered as relevant item.
Value of the each non-zero entry considered as relevance for calculation of |
... |
other arguments (not used at the moment) |
Examples
predictions = matrix(
c(5L, 7L, 9L, 2L),
nrow = 1
)
actual = matrix(
c(0, 0, 0, 0, 1, 0, 1, 0, 1, 0),
nrow = 1
)
actual = as(actual, "RsparseMatrix")
identical(rsparse::ap_k(predictions, actual), 1)