precision
logger = logging.getLogger(__name__) module-attribute ¶
PrecisionK ¶
Bases: ListwiseMetricK
Computes the fraction of top-K recommendations that correspond to true interactions.
Given the prediction and true interaction in binary representation, the matrix is multiplied elementwise. These will result in the true positives to be 1 and the false positives to be 0. The sum of the resulting true positives is then divided by the number of actual top-K interactions to get the precision on user level.
In simple terms, precision is the ratio of correctly predicted positive observations to the total predictions made.
Precision is computed per user as:
.. math::
\text{Precision}(u) = \frac{\sum\limits_{i \in \text{Top-K}(u)} y^{true}_{u,i}}{K}\
ref: RecPack
:param K: Size of the recommendation list consisting of the Top-K item predictions. :type K: int
Source code in src/recnexteval/metrics/ranking/precision.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
IS_BASE = False class-attribute instance-attribute ¶
name property ¶
Name of the metric.
params property ¶
Parameters of the metric.
identifier property ¶
Identifier of the object.
Identifier is made by combining the class name with the parameters passed at construction time.
Constructed by recreating the initialisation call. Example: Algorithm(param_1=value)
:return: Identifier of the object
micro_result property ¶
User level results for the metric.
Contains an entry for every user.
:return: The results DataFrame with columns: user_id, score :rtype: pd.DataFrame
macro_result property ¶
Global metric value obtained by taking the average over all users.
:raises ValueError: If the metric has not been calculated yet. :return: The global metric value. :rtype: float, optional
is_time_aware property ¶
Whether the metric is time-aware.
timestamp_limit property ¶
The timestamp limit for the metric.
num_items property ¶
Dimension of the item-space in both y_true and y_pred
num_users property ¶
Dimension of the user-space in both y_true and y_pred after elimination of users without interactions in y_true.
K = K instance-attribute ¶
col_names property ¶
The names of the columns in the results DataFrame.
get_params() ¶
Get the parameters of the metric.
Source code in src/recnexteval/metrics/core/base.py
53 54 55 56 57 | |
calculate(y_true, y_pred) ¶
Calculates this metric for all nonzero users in y_true, given true labels and predicted scores.
Source code in src/recnexteval/metrics/core/base.py
116 117 118 119 120 121 | |
prepare_matrix(y_true, y_pred) ¶
Source code in src/recnexteval/metrics/core/top_k.py
57 58 59 60 | |