Splitting - API Reference¶
warprec.data.splitting.splitter.Splitter
¶
Splitter class will handle the splitting of the data.
Source code in warprec/data/splitting/splitter.py
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 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 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
filter_sets(train_set, evaluation_set, user_id_label='user_id', item_id_label='item_id', eval_set_name=None)
¶
Filter the evaluation set based on the train set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_set
|
DataFrame[Any]
|
The training set. |
required |
evaluation_set
|
DataFrame[Any]
|
The evaluation set to be filtered. |
required |
user_id_label
|
str
|
The user ID label. |
'user_id'
|
item_id_label
|
str
|
The item ID label. |
'item_id'
|
eval_set_name
|
Optional[str]
|
The name of the evaluation set. Used for logging purposes. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame[Any]
|
DataFrame[Any]: The filtered evaluation set. |
Source code in warprec/data/splitting/splitter.py
process_split(data, strategy, user_id_label='user_id', item_id_label='item_id', rating_label='rating', timestamp_label='timestamp', ratio=None, k=None, folds=None, timestamp=None, seed=42)
¶
Process the splitting based on the selected strategy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FrameT
|
The DataFrame to be splitted. |
required |
strategy
|
SplittingStrategies
|
The splitting strategy to use. |
required |
user_id_label
|
str
|
The user_id label. |
'user_id'
|
item_id_label
|
str
|
The item_id label. |
'item_id'
|
rating_label
|
str
|
The rating label. |
'rating'
|
timestamp_label
|
str
|
The timestamp label. |
'timestamp'
|
ratio
|
Optional[float]
|
The ratio value. |
None
|
k
|
Optional[int]
|
The k value. |
None
|
folds
|
Optional[int]
|
The folds value. |
None
|
timestamp
|
Optional[Union[int, str]]
|
The timestamp to be used for the splitting. Either an integer or 'best'. |
None
|
seed
|
int
|
The seed value. Defaults to 42. |
42
|
Returns:
| Type | Description |
|---|---|
List[Tuple[DataFrame[Any], DataFrame[Any]]]
|
List[Tuple[DataFrame[Any], DataFrame[Any]]]: A list of tuples containing the train and evaluation sets. |
Source code in warprec/data/splitting/splitter.py
split_transaction(data, user_id_label='user_id', item_id_label='item_id', rating_label='rating', timestamp_label='timestamp', test_strategy=None, test_ratio=None, test_k=None, test_folds=None, test_timestamp=None, test_seed=42, val_strategy=None, val_ratio=None, val_k=None, val_folds=None, val_timestamp=None, val_seed=42)
¶
The main method of the class. This method must be called to split the data.
When called, this method will return the splitting calculated by the splitting method selected in the configuration file.
This method accepts transaction data, and will return the DataFrames of split data.
A transaction is defined by at least a user_id, an item_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FrameT
|
The DataFrame to be splitted. |
required |
user_id_label
|
str
|
The user_id label. |
'user_id'
|
item_id_label
|
str
|
The item_id label. |
'item_id'
|
rating_label
|
str
|
The rating label. |
'rating'
|
timestamp_label
|
str
|
The timestamp label. |
'timestamp'
|
test_strategy
|
Optional[SplittingStrategies | str]
|
The splitting strategy to use for test set. |
None
|
test_ratio
|
Optional[float]
|
The ratio value for test set. |
None
|
test_k
|
Optional[int]
|
The k value for test set. |
None
|
test_folds
|
Optional[int]
|
The folds value for test set. |
None
|
test_timestamp
|
Optional[Union[int, str]]
|
The timestamp to be used for the test set. Either an integer or 'best'. |
None
|
test_seed
|
int
|
The seed value for test set. Defaults to 42. |
42
|
val_strategy
|
Optional[SplittingStrategies | str]
|
The splitting strategy to use for validation set. |
None
|
val_ratio
|
Optional[float]
|
The ratio value for validation set. |
None
|
val_k
|
Optional[int]
|
The k value for validation set. |
None
|
val_folds
|
Optional[int]
|
The folds value for validation set. |
None
|
val_timestamp
|
Optional[Union[int, str]]
|
The timestamp to be used for the validation set. Either an integer or 'best'. |
None
|
val_seed
|
int
|
The seed value for validation set. Defaults to 42. |
42
|
Returns:
| Type | Description |
|---|---|
Tuple[DataFrame[Any], Optional[List[Tuple[DataFrame[Any], DataFrame[Any]]] | DataFrame[Any]], DataFrame[Any]]
|
Tuple[DataFrame[Any], Optional[List[Tuple[DataFrame[Any], DataFrame[Any]]] | DataFrame[Any]], DataFrame[Any]]: - DataFrame[Any]: The original train data, used to train the final model of the experiment. - Optional[List[Tuple[DataFrame[Any], DataFrame[Any]]] | DataFrame[Any]]: Either return a list of tuples - DataFrame[Any]: The train data used to train the model. - DataFrame[Any]: The validation data used to evaluate the model during training. or just a single DataFrame representing the validation set. - DataFrame[Any]: The unique test data, used at the end of the experiment to evaluate the model. |
Source code in warprec/data/splitting/splitter.py
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 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 | |
warprec.data.splitting.strategies.SplittingStrategy
¶
Bases: ABC
Abstract definition of a splitting strategy.
Source code in warprec/data/splitting/strategies.py
__call__(data, **kwargs)
¶
This method will split the data in train/eval split.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
FrameT
|
The FrameT to be splitted. |
required |
**kwargs
|
Any
|
The additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
List[Tuple[DataFrame[Any], DataFrame[Any]]]
|
List[Tuple[DataFrame[Any], DataFrame[Any]]]: - DataFrame[Any]: First partition of splitted data. - DataFrame[Any]: Second partition of splitted data. |