Recall
Что такое Recall?
Пример
Реализация на Python
def recall(recommendation, targets):
"""Computes the recall at k for a single user."""
if not isinstance(recommendation, (list, np.ndarray)):
raise TypeError(f'recommendation must be a list or numpy.array, not {type(recommendation)}')
if not isinstance(targets, (list, np.ndarray)):
raise TypeError(f'targets must be a list or numpy.array, not {type(targets)}')
if len(targets) == 0:
return 0.0
flags = np.isin(recommendation, targets)
recall = float(np.sum(flags)) / len(targets)
return recall
def recall_at_k(dataframe, k=5, user_col='user', item_col='item', score_col='score', target_col='target'):
"""Computes the recall at k for each user and returns the average."""
grouped = dataframe.groupby(user_col)
recalls = grouped.apply(lambda user_data: recall(
user_data.sort_values(score_col, ascending=False)[item_col].values[:k],
user_data[user_data[target_col] == 1][item_col].values
))
return recalls.mean()