autointent.metrics.retrieval_hit_rate#

autointent.metrics.retrieval_hit_rate(query_labels, candidates_labels, k=None)#

Calculate the hit rate at position k.

The hit rate is calculated as:

Hit Rate=i=1N1(yquery,iycandidates,i(1:k))N

where:

  • N is the total number of queries,

  • yquery,i is the true label for the i-th query,

  • ycandidates,i(1:k) is the set of top-k predicted labels for the i-th query,

  • 1(condition) is the indicator function that equals 1 if the condition

is true and 0 otherwise.

Parameters:
  • query_labels (autointent.metrics.custom_types.LABELS_VALUE_TYPE) – For each query, this list contains its class labels

  • candidates_labels (autointent.metrics.custom_types.CANDIDATE_TYPE) – For each query, these lists contain class labels of items ranked by a retrieval model (from most to least relevant)

  • k (int | None) – Number of top items to consider for each query

Returns:

Score of the retrieval metric

Return type:

float