recpack.scenarios.LastItemPrediction
- class recpack.scenarios.LastItemPrediction(validation=False, seed=None, n_most_recent_in=2147483647)
Predict a user’s next interaction.
Scenario frequently used in evaluation of sequential recommendation algorithms.
Warning
The scenario can only be used when the dataset has timestamp information, because the order of interactions is needed to correctly split the data.
The scenario splits the data such that the last interaction of a user is the target for prediction, while the earlier ones are used for training and as history.
full_training_data
contains all but the most recent interaction for each of the users.test_data_in
: contains then_most_recent_in
interactions before the last interaction of each user.test_data_out
contains the last interaction of all users.validation_training_data
contains all but the most recent interaction of each user in the full training dataset.validation_data_in
contains then_most_recent_in
interactions before the last interaction of each user in the full training dataset.validation_data_out
contains the most recent interaction of each user in the full training dataset
Example
As an example, we split this data with
validation = True
andn_most_recent_in = 1
:time 0 1 2 3 4 5 Alice X X X Bob X X X X
would yield full_training_data:
time 0 1 2 3 4 5 Alice X X Bob X X X
validation_training_data:
time 0 1 2 3 4 5 Alice X Bob X X
validation_data_in:
time 0 1 2 3 4 5 Alice X Bob X
validation_data_out:
time 0 1 2 3 4 5 Alice X Bob X
test_data_in:
time 0 1 2 3 4 5 Alice X Bob X
test_data_out:
time 0 1 2 3 4 5 Alice X Bob X
- Parameters
validation (boolean, optional) – construct validation datasets if True, else split without validation data into only a full training and test dataset.
seed (int, optional) – Seed for randomisation parts of the scenario. This scenario is deterministic, so changing seed does not matter. Defaults to None, so random seed will be generated.
n_most_recent_in (int, optional) – How much of the historic events to use as input history. Defaults to the maximal integer value.
Methods
split
(data_m)Splits
data_m
according to the scenario.Attributes
The full training dataset, which should be used for a final training after hyper parameter optimisation.
The test dataset.
Fold-in part of the test dataset
Held-out part of the test dataset
The validation dataset.
Fold-in part of the validation dataset
Held-out part of the validation dataset
The training data to be used during validation.
- property full_training_data: recpack.matrix.interaction_matrix.InteractionMatrix
The full training dataset, which should be used for a final training after hyper parameter optimisation.
- Returns
Interaction Matrix of training interactions.
- Return type
- split(data_m: recpack.matrix.interaction_matrix.InteractionMatrix) None
Splits
data_m
according to the scenario.After splitting properties
training_data
,validation_data
andtest_data
can be used to retrieve the splitted data.- Parameters
data_m – Interaction matrix that should be split.
- property test_data: Tuple[recpack.matrix.interaction_matrix.InteractionMatrix, recpack.matrix.interaction_matrix.InteractionMatrix]
The test dataset. Consist of a fold-in and hold-out set of interactions.
Data is processed such that both matrices contain the exact same users. Users that were present in only one of the matrices and not in the other are removed.
- Returns
Test data matrices as InteractionMatrix in, InteractionMatrix out.
- Return type
Tuple[InteractionMatrix, InteractionMatrix]
- property test_data_in
Fold-in part of the test dataset
- property test_data_out
Held-out part of the test dataset
- property validation_data: Optional[Tuple[recpack.matrix.interaction_matrix.InteractionMatrix, recpack.matrix.interaction_matrix.InteractionMatrix]]
The validation dataset. Consist of a fold-in and hold-out set of interactions.
Data is processed such that both matrices contain the exact same users. Users that were present in only one of the matrices and not in the other are removed.
- Returns
Validation data matrices as InteractionMatrix in, InteractionMatrix out.
- Return type
Tuple[InteractionMatrix, InteractionMatrix]
- property validation_data_in
Fold-in part of the validation dataset
- property validation_data_out
Held-out part of the validation dataset
- property validation_training_data: recpack.matrix.interaction_matrix.InteractionMatrix
The training data to be used during validation.