metrics: Ranking Metrics for Top-K Items

metricsR 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:

  1. predictions = integer matrix with item indices (correspond to column numbers in actual)

  2. predictions = character matrix with item identifiers (characters which correspond to colnames(actual)) which has attribute "indices" (integer matrix with item indices which correspond to column numbers in actual).

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 ndcg@k. It should inherit from Matrix::sparseMatrix. Internally Matrix::RsparseMatrix is used.

...

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)

rsparse documentation built on Sept. 12, 2022, 1:06 a.m.