calc_confusions

rectools.metrics.classification.calc_confusions(merged: DataFrame, k: int) DataFrame[source]

Calculate some intermediate metrics from prepared data (it’s a helper function).

For each user (Columns.User) the following metrics are calculated:
  • LIKED - number of items the user has interacted (bought, liked) with;

  • TP - number of relevant recommendations among the first k items at the top of recommendation list;

  • FP - number of non-relevant recommendations among the first k items of recommendation list;

  • FN - number of items the user has interacted with but that weren’t recommended (in top k).

Parameters
  • merged (pd.DataFrame) – Result of merging recommendations and interactions tables. Can be obtained using merge_reco function.

  • k (int) – Number of items at the top of recommendations list that will be used to calculate metric.

Returns

Table with columns: Columns.User, LIKED, TP, FP, FN.

Return type

pd.DataFrame

Notes

left = all - K TP = sum(rank) FP = K - TP FN = liked - TP TN = all - K - FN = left - FN = left - liked + TP