powered by
Determines if the true class label is among the top k predicted probabilities for each observation.
k
topk(prob, observed, k)
A data.frame with columns topk (logical indicator: TRUE if observed class is in top-k) and observed.
data.frame
topk
TRUE
observed
Numeric matrix of predicted probabilities (observations x classes). Column names must correspond to class labels.
Factor or vector of observed class labels. Must be present in colnames(prob).
colnames(prob)
Integer; the number of top probabilities to consider.
Other classifier evaluation: rank_score()
rank_score()
probs <- matrix(c(0.1, 0.9, 0.8, 0.2, 0.3, 0.7), 3, 2, byrow=TRUE, dimnames = list(NULL, c("A", "B"))) obs <- factor(c("B", "A", "B")) topk(probs, obs, k=1) topk(probs, obs, k=2)
Run the code above in your browser using DataLab