stream
EvaluatorStreamer dataclass ¶
Bases: EvaluatorBase
Evaluation via streaming through API.
The diagram below shows the diagram of the streamer evaluator for the sliding window setting. Instead of the pipeline, we allow the user to stream the data release to the algorithm. The data communication is shown between the evaluator and the algorithm. Note that while only 2 splits are shown here, the evaluator will continue to stream the data until the end of the setting where there are no more splits.

This class exposes a few of the core API that allows the user to stream the evaluation process. The following API are exposed:
- :meth:
register_algorithm - :meth:
start_stream - :meth:
get_unlabeled_data - :meth:
submit_prediction
The programmer can take a look at the specific method for more details on the implementation of the API. The methods are designed with the methodological approach that the algorithm is decoupled from the the evaluating platform. And thus, the evaluator will only provide the necessary data to the algorithm and evaluate the prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric_entries | list[MetricEntry] | list of metric entries. | required |
setting | Setting | Setting object. | required |
metric_k | int | Number of top interactions to consider. | required |
ignore_unknown_user | bool | To ignore unknown users. | False |
ignore_unknown_item | bool | To ignore unknown items. | False |
seed | int | Random seed for the evaluator. | 42 |
Source code in src/recnexteval/evaluators/stream/evaluator.py
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 52 53 54 55 56 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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
metric_entries instance-attribute ¶
setting instance-attribute ¶
metric_k instance-attribute ¶
ignore_unknown_user = False class-attribute instance-attribute ¶
ignore_unknown_item = False class-attribute instance-attribute ¶
seed = 42 class-attribute instance-attribute ¶
user_item_base = field(default_factory=UserItemKnowledgeBase) class-attribute instance-attribute ¶
state property ¶
metric_results(level=MetricLevelEnum.MACRO, only_current_timestamp=False, filter_timestamp=None, filter_algo=None) ¶
Results of the metrics computed.
Computes the metrics of all algorithms based on the level specified and return the results in a pandas DataFrame. The results can be filtered based on the algorithm name and the current timestamp.
Specifics¶
- User level: User level metrics computed across all timestamps.
- Window level: Window level metrics computed across all timestamps. This can be viewed as a macro level metric in the context of a single window, where the scores of each user is averaged within the window.
- Macro level: Macro level metrics computed for entire timeline. This score is computed by averaging the scores of all windows, treating each window equally.
- Micro level: Micro level metrics computed for entire timeline. This score is computed by averaging the scores of all users, treating each user and the timestamp the user is in as unique contribution to the overall score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level | MetricLevelEnum | Literal['macro', 'micro', 'window', 'user'] | Level of the metric to compute, defaults to "macro". | MACRO |
only_current_timestamp | None | bool | Filter only the current timestamp, defaults to False. | False |
filter_timestamp | None | int | Timestamp value to filter on, defaults to None. If both | None |
filter_algo | None | str | Algorithm name to filter on, defaults to None. | None |
Returns:
| Type | Description |
|---|---|
DataFrame | Dataframe representation of the metric. |
Source code in src/recnexteval/evaluators/core/base.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
plot_macro_level_metric() ¶
Source code in src/recnexteval/evaluators/core/base.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | |
plot_micro_level_metric() ¶
Source code in src/recnexteval/evaluators/core/base.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
plot_window_level_metric() ¶
Source code in src/recnexteval/evaluators/core/base.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
restore() ¶
Restore the generators before pickling.
This method is used to restore the generators after loading the object from a pickle file.
Source code in src/recnexteval/evaluators/core/base.py
310 311 312 313 314 315 316 317 | |
current_step() ¶
Return the current step of the evaluator.
Returns:
| Type | Description |
|---|---|
int | Current step of the evaluator. |
Source code in src/recnexteval/evaluators/core/base.py
319 320 321 322 323 324 325 | |
start_stream() ¶
Start the streaming process.
Warning
Once start_stream is called, the evaluator cannot register any new algorithms.
Raises:
| Type | Description |
|---|---|
ValueError | If the stream has already started. |
Source code in src/recnexteval/evaluators/stream/evaluator.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
register_model(algorithm, algorithm_name=None) ¶
Register the algorithm with the evaluator.
This method is called to register the algorithm with the evaluator. The method will assign a unique identifier to the algorithm and store the algorithm in the registry.
Warning
Once start_stream is called, the evaluator cannot register any new algorithms.
Source code in src/recnexteval/evaluators/stream/evaluator.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
get_algorithm_state(algorithm_id) ¶
Get the state of the algorithm.
Source code in src/recnexteval/evaluators/stream/evaluator.py
122 123 124 | |
get_all_algorithm_status() ¶
Get the status of all algorithms.
Source code in src/recnexteval/evaluators/stream/evaluator.py
126 127 128 | |
load_next_window() ¶
Source code in src/recnexteval/evaluators/stream/evaluator.py
130 131 132 133 134 | |
get_training_data(algo_id) ¶
Get training data for the algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algo_id | UUID | Unique identifier of the algorithm. | required |
Raises:
| Type | Description |
|---|---|
ValueError | If the stream has not started. |
Returns:
| Type | Description |
|---|---|
InteractionMatrix | The training data for the algorithm. |
Source code in src/recnexteval/evaluators/stream/evaluator.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
get_unlabeled_data(algo_id) ¶
Get unlabeled data for the algorithm.
This method is called to get the unlabeled data for the algorithm. The unlabeled data is the data that the algorithm will predict. It will contain (user_id, -1) pairs, where the value -1 indicates that the item is to be predicted.
Source code in src/recnexteval/evaluators/stream/evaluator.py
179 180 181 182 183 184 185 186 187 188 189 190 191 | |
submit_prediction(algo_id, X_pred) ¶
Submit the prediction of the algorithm.
This method is called to submit the prediction of the algorithm. There are a few checks that are done before the prediction is evaluated by calling :meth:_evaluate_algo_pred.
Once the prediction is evaluated, the method will update the state of the algorithm to PREDICTED.
Source code in src/recnexteval/evaluators/stream/evaluator.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
EvaluationStrategy ¶
Bases: ABC
Abstract strategy for different evaluation modes
Source code in src/recnexteval/evaluators/stream/strategy.py
6 7 8 9 10 11 12 | |
should_advance_window(algo_state_mgr, current_step, total_steps) abstractmethod ¶
Determine if should advance to next window
Source code in src/recnexteval/evaluators/stream/strategy.py
9 10 11 12 | |
SingleTimePointStrategy ¶
Bases: EvaluationStrategy
Strategy for sliding window evaluation
Source code in src/recnexteval/evaluators/stream/strategy.py
27 28 29 30 31 32 | |
should_advance_window(algo_state_mgr, current_step, total_steps) ¶
Advance only when all algorithms predicted
Source code in src/recnexteval/evaluators/stream/strategy.py
30 31 32 | |
SlidingWindowStrategy ¶
Bases: EvaluationStrategy
Strategy for sliding window evaluation
Source code in src/recnexteval/evaluators/stream/strategy.py
15 16 17 18 19 20 21 22 23 24 | |
should_advance_window(algo_state_mgr, current_step, total_steps) ¶
Advance only when all algorithms predicted
Source code in src/recnexteval/evaluators/stream/strategy.py
18 19 20 21 22 23 24 | |