top_k
logger = logging.getLogger(__name__) module-attribute ¶
TopKAlgorithm ¶
Bases: Algorithm
Base algorithm for algorithms that recommend top-K items for every user.
Source code in src/recnexteval/algorithms/core/top_k.py
12 13 14 15 16 17 | |
K = K instance-attribute ¶
name property ¶
Name of the object's class.
:return: Name of the object's class :rtype: str
params property ¶
Parameters of the object.
:return: Parameters of the object :rtype: dict
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 :rtype: str
IS_BASE = True class-attribute instance-attribute ¶
ITEM_USER_BASED instance-attribute ¶
seed = 42 instance-attribute ¶
rand_gen = np.random.default_rng(seed=(self.seed)) instance-attribute ¶
description property ¶
Description of the algorithm.
:return: Description of the algorithm :rtype: str
get_params() abstractmethod ¶
Get the parameters of the object.
:return: Parameters of the object :rtype: dict
Source code in src/recnexteval/models/base.py
38 39 40 41 42 43 44 45 | |
get_default_params() classmethod ¶
Get default parameters without instantiation.
Uses inspect.signature to extract init parameters and their default values without instantiating the class.
Returns:
| Type | Description |
|---|---|
dict | Dictionary of parameter names to default values. |
dict | Parameters without defaults map to None. |
Source code in src/recnexteval/algorithms/core/base.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
set_params(**params) ¶
Set the parameters of the estimator.
:param params: Estimator parameters :type params: dict
Source code in src/recnexteval/algorithms/core/base.py
94 95 96 97 98 99 100 | |
fit(X) ¶
Fit the model to the input interaction matrix.
The input data is transformed to the expected type using :meth:_transform_fit_input. The fitting is done using the :meth:_fit method. Finally the method checks that the fitting was successful using :meth:_check_fit_complete.
:param X: The interactions to fit the model on. :type X: InteractionMatrix :return: Fitted algorithm :rtype: Algorithm
Source code in src/recnexteval/algorithms/core/base.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
predict(X) ¶
Predicts scores, given the interactions in X
The input data is transformed to the expected type using :meth:_transform_predict_input. The predictions are made using the :meth:_predict method. Finally the predictions are then padded with random items for users that are not in the training data.
:param X: interactions to predict from. :type X: InteractionMatrix :return: The recommendation scores in a sparse matrix format. :rtype: csr_matrix
Source code in src/recnexteval/algorithms/core/base.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
TopKItemSimilarityMatrixAlgorithm ¶
Bases: TopKAlgorithm
Base algorithm for algorithms that fit an item to item similarity model with K similar items for every item
Model that encodes the similarity between items is expected under the similarity_matrix_ attribute.
This matrix should have shape (|items| x |items|). This can be dense or sparse matrix depending on the algorithm used.
Predictions are made by computing the dot product of the history vector of a user and the similarity matrix.
Usually a new algorithm will have to implement just the :meth:_fit method, to construct the self.similarity_matrix_ attribute.
Source code in src/recnexteval/algorithms/core/top_k.py
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 52 53 54 55 56 57 58 59 60 61 | |
similarity_matrix_ instance-attribute ¶
name property ¶
Name of the object's class.
:return: Name of the object's class :rtype: str
params property ¶
Parameters of the object.
:return: Parameters of the object :rtype: dict
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 :rtype: str
IS_BASE = True class-attribute instance-attribute ¶
ITEM_USER_BASED instance-attribute ¶
seed = 42 instance-attribute ¶
rand_gen = np.random.default_rng(seed=(self.seed)) instance-attribute ¶
description property ¶
Description of the algorithm.
:return: Description of the algorithm :rtype: str
K = K instance-attribute ¶
get_params() abstractmethod ¶
Get the parameters of the object.
:return: Parameters of the object :rtype: dict
Source code in src/recnexteval/models/base.py
38 39 40 41 42 43 44 45 | |
get_default_params() classmethod ¶
Get default parameters without instantiation.
Uses inspect.signature to extract init parameters and their default values without instantiating the class.
Returns:
| Type | Description |
|---|---|
dict | Dictionary of parameter names to default values. |
dict | Parameters without defaults map to None. |
Source code in src/recnexteval/algorithms/core/base.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
set_params(**params) ¶
Set the parameters of the estimator.
:param params: Estimator parameters :type params: dict
Source code in src/recnexteval/algorithms/core/base.py
94 95 96 97 98 99 100 | |
fit(X) ¶
Fit the model to the input interaction matrix.
The input data is transformed to the expected type using :meth:_transform_fit_input. The fitting is done using the :meth:_fit method. Finally the method checks that the fitting was successful using :meth:_check_fit_complete.
:param X: The interactions to fit the model on. :type X: InteractionMatrix :return: Fitted algorithm :rtype: Algorithm
Source code in src/recnexteval/algorithms/core/base.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
predict(X) ¶
Predicts scores, given the interactions in X
The input data is transformed to the expected type using :meth:_transform_predict_input. The predictions are made using the :meth:_predict method. Finally the predictions are then padded with random items for users that are not in the training data.
:param X: interactions to predict from. :type X: InteractionMatrix :return: The recommendation scores in a sparse matrix format. :rtype: csr_matrix
Source code in src/recnexteval/algorithms/core/base.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |