Precision

class rectools.metrics.classification.Precision(k: int, r_precision: bool = False)[source]

Bases: SimpleClassificationMetric

Ratio of relevant items among top-k recommended items.

The Precision@k equals to tp / k where tp is the number of relevant recommendations among first k items in the top of recommendation list.

The R-Precision equals to tp / min(k, tp+fn) where tp + fn is the total number of items in user test interactions.

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

  • r_precision (bool, default False) – Whether to calculate R-Precision instead of simple Precision. If True number of user true positives (tp) in recommendations will be divided by minimum of k and number of user test positives (tp+fn) instead of division by k.

Inherited-members

Methods

calc(reco, interactions)

Calculate metric value.

calc_from_confusion_df(confusion_df)

Calculate metric value from prepared confusion matrix.

calc_per_user(reco, interactions)

Calculate metric values for all users.

calc_per_user_from_confusion_df(confusion_df)

Calculate metric values for all users from prepared confusion matrix.

Attributes

r_precision