metrax.RecallAtK#

class metrax.RecallAtK(total: Array, count: Array)#

Bases: TopKRankingMetric

Computes R@k (recall at k) metrics.

Recall at k (R@k) is a metric that measures the proportion of relevant items that are found in the top k recommendations, out of the total number of relevant items for a given user/query. It answers the question: “Out of all the items that are truly relevant, how many did we find in the top K?”

Given the top \(K\) recommendations, R@K is calculated as:

\[Recall@K = \frac{\text{Number of relevant items in top K}}{\text{Total number of relevant items}}\]
__init__(total: Array, count: Array) None#

Methods

__init__(total, count)

compute()

Computes final metrics from intermediate values.

compute_value()

Wraps compute() and returns a values.Value.

empty()

Returns an empty instance (i.e. .merge(Metric.empty()) is a no-op).

from_fun(fun)

Calls cls.from_model_output with the return value from fun.

from_model_output(predictions, labels, ks)

Creates a metric instance from model output.

from_output(name)

Calls cls.from_model_output with model output named name.

merge(other)

Returns Metric that is the accumulation of self and other.

reduce()

Reduces the metric along it first axis by calling _reduce_merge().

replace(**updates)

Returns a new object replacing the specified fields with new values.

Attributes

total

count

__init__(total: Array, count: Array) None#
replace(**updates)#

Returns a new object replacing the specified fields with new values.