Input/Output Reference
This section provides a detailed API reference for all modules related to data input/output and framework interoperability in the datarec library.
Readers return RawData, writers accept RawData or DataRec, and framework exporters convert datasets to external formats.
On This Page
Minimal usage:
from datarec.io.readers.transactions.tabular import read_transactions_tabular
from datarec.io.writers.transactions.tabular import write_transactions_tabular
raw = read_transactions_tabular(
"data/interactions.csv",
sep=",",
user_col="user",
item_col="item",
rating_col="rating",
)
write_transactions_tabular(raw, "out/interactions.tsv", sep="\t")
Core I/O Modules
These modules handle the fundamental tasks of reading, writing, and representing raw data.
RawData
Container for raw datasets in DataRec.
Wraps a pandas.DataFrame and stores metadata about user, item, rating, and timestamp columns.
Provides lightweight methods for slicing, copying, and merging data.
Source code in datarec/io/rawdata.py
8 9 10 11 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 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 | |
__init__(data=None, header=False, user=None, item=None, rating=None, timestamp=None, user_encoder=None, item_encoder=None)
Initialize a RawData object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame of the dataset. Defaults to None. |
None
|
header
|
bool
|
Whether the file has a header. Defaults to False. |
False
|
user
|
str
|
Column name for user IDs. |
None
|
item
|
str
|
Column name for item IDs. |
None
|
rating
|
str
|
Column name for ratings. |
None
|
timestamp
|
str
|
Column name for timestamps. |
None
|
user_encoder
|
dict | None
|
Optional user encoding mapping. |
None
|
item_encoder
|
dict | None
|
Optional item encoding mapping. |
None
|
Source code in datarec/io/rawdata.py
append(new_data)
Append new rows to the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_data
|
DataFrame
|
DataFrame to append. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
copy(deep=True)
Make a copy of the dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deep
|
bool
|
If True, return a deep copy of the dataset. |
True
|
Returns:
| Type | Description |
|---|---|
RawData
|
A copy of the dataset. |
Source code in datarec/io/rawdata.py
__repr__()
__len__()
__getitem__(idx)
Return the item at the given index. Args: idx: index of the item to return.
Returns:
| Type | Description |
|---|---|
RawData
|
the sample at the given index. |
__add__(other)
Concatenate two RawData objects. Args: other (RawData): the other RawData to concatenate.
Returns:
| Type | Description |
|---|---|
RawData
|
the concatenated RawData object. |
Source code in datarec/io/rawdata.py
__iter__()
__check_rawdata_compatibility__(rawdata)
Check compatibility between RawData objects. Args: rawdata (RawData): RawData object to check.
Returns:
| Type | Description |
|---|---|
bool
|
True if compatibility is verified. |
Source code in datarec/io/rawdata.py
__check_rawdata_compatibility__(rawdata1, rawdata2)
Check compatibility between two RawData objects. Args: rawdata1 (RawData): First RawData object to check. rawdata2 (RawData): Second RawData object to check.
Returns:
| Type | Description |
|---|---|
bool
|
True if compatibility is verified. |
Source code in datarec/io/rawdata.py
read_sequences_json(filepath, *, user_col='user', item_col='item', rating_col=None, timestamp_col=None, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a JSON file representing sequential interaction data in the form:
{ "user_id": [ { "item": ..., "rating": ..., "timestamp": ... }, ... ], ... }
Converts it into a transactional RawData format with one row per interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the JSON file. |
required |
user_col
|
str
|
Name assigned to the user column in the output. |
'user'
|
item_col
|
str
|
Key containing the item field inside each event. |
'item'
|
rating_col
|
Optional[str]
|
Key containing the rating field inside each event. |
None
|
timestamp_col
|
Optional[str]
|
Key containing the timestamp field inside each event. |
None
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
A DataRec object containing all interactions exploded row-by-row. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/sequences/json.py
read_sequences_json_array(filepath, *, user_col='user', item_col='item', rating_col=None, timestamp_col=None, sequence_key='sequence', dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a JSON file representing sequential interaction data in the form of an ARRAY of user-sequence objects, e.g.:
[
{
"user": 0,
"sequence": [
{ "item": 1, "rating": 1, "timestamp": "001" },
{ "item": 2, "rating": 1, "timestamp": "022" }
]
},
{
"user": 1,
"sequence": [
{ "item": 1, "rating": 4, "timestamp": "011" }
]
}
]
and converts it into a transactional RawData format with one row per interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the JSON file. |
required |
user_col
|
str
|
Name assigned to the user column in the output. Also used as the key to read the user identifier in each top-level object. |
'user'
|
item_col
|
str
|
Key containing the item field inside each event. |
'item'
|
rating_col
|
Optional[str]
|
Key containing the rating field inside each event. |
None
|
timestamp_col
|
Optional[str]
|
Key containing the timestamp field inside each event. |
None
|
sequence_key
|
str
|
Key containing the list of events for each user. |
'sequence'
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
A DataRec object containing all interactions exploded row-by-row. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/sequences/json.py
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 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 309 310 311 | |
read_sequences_json_items(filepath, *, user_col='user', item_col='item', rating_col=None, timestamp_col=None, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a JSON file representing sequential interaction data in the form:
{ "user_id": [item_id, item_id, ...], ... }
Each list contains item identifiers only (no event objects). The data is converted into a transactional RawData format with one row per interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the JSON file. |
required |
user_col
|
str
|
Name assigned to the user column in the output. |
'user'
|
item_col
|
str
|
Name assigned to the item column in the output. |
'item'
|
rating_col
|
Optional[str]
|
Not supported for item-only JSON. |
None
|
timestamp_col
|
Optional[str]
|
Not supported for item-only JSON. |
None
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns: DataRec: A DataRec object containing all interactions exploded row-by-row. (Returned via @annotate_datarec_output, which wraps the RawData.)
Source code in datarec/io/readers/sequences/json.py
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 | |
read_sequence_tabular_inline(filepath, *, user_col='user', sequence_col='sequence', sequence_sep=' ', timestamp_col='timestamp', meta_cols=None, col_sep=',', header=None, cols=None, engine='c', fallback_engine='python', stream=False, encode_ids=False, chunksize=100000, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a file where interaction sequences are stored in a single string column.
Example: user_id,sequence -> 70,"495 1631 2317"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the CSV file. |
required |
user_col
|
str
|
Column name containing the user ID. |
'user'
|
sequence_col
|
str
|
Column containing the serialized interaction sequence. |
'sequence'
|
sequence_sep
|
str
|
Separator used inside the sequence string. |
' '
|
timestamp_col
|
Optional[str]
|
Column name for timestamp (if present). |
'timestamp'
|
meta_cols
|
Optional[List[str]]
|
Additional metadata columns to keep. |
None
|
col_sep
|
str
|
Column separator used in the CSV file. |
','
|
header
|
Union[int, List[int], str, None]
|
Row number for the header. |
None
|
cols
|
Optional[List[str]]
|
Explicit column names if the file has no header. |
None
|
engine
|
str
|
Pandas CSV engine to use ("c" or "python"). Defaults to "c" with automatic
fallback to |
'c'
|
fallback_engine
|
str
|
Engine to try if the primary one fails. Defaults to "python". |
'python'
|
stream
|
bool
|
If True, process the file in chunks to reduce peak memory. |
False
|
encode_ids
|
bool
|
If True, encode user/item to int ids using IncrementalEncoder (streaming or full). |
False
|
chunksize
|
int
|
Number of rows per chunk when streaming. |
100000
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
Transactional data. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/sequences/tabular.py
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 | |
read_sequence_tabular_wide(filepath, *, user_col='user', item_col='item', col_sep='\t', header=None, encode_ids=False, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a file containing variable-length interaction sequences (ragged).
Example: u0 i0 i1 i3
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the text/CSV file. |
required |
user_col
|
str
|
Name to assign to the user column. |
'user'
|
item_col
|
str
|
Name to assign to the item column. |
'item'
|
col_sep
|
str
|
Delimiter used in the file. |
'\t'
|
header
|
Optional[int]
|
Row number (0-indexed) to use as the header (to be skipped). |
None
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
Transactional DataFrame. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/sequences/tabular.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
read_sequence_tabular_implicit(filepath, *, user_col='sequence_id', item_col='item', col_sep=' ', header=None, drop_length_col=True, encode_ids=False, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a tabular file where each row represents a sequence with an implicit identifier (row-based), optionally starting with a declared sequence length.
Example
3 10 20 30 2 11 42
Each row is interpreted as a distinct sequence (pseudo-user). The first column may represent the declared sequence length and is ignored by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the text/CSV file. |
required |
user_col
|
str
|
Name assigned to the implicit sequence identifier column. |
'sequence_id'
|
item_col
|
str
|
Name assigned to the item column. |
'item'
|
col_sep
|
str
|
Delimiter used in the file. |
' '
|
header
|
Optional[int]
|
Optional row index to skip as header. |
None
|
drop_length_col
|
bool
|
If True, the first column is treated as sequence length and discarded. |
True
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
Transactional DataFrame where each sequence is treated as a pseudo-user. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/sequences/tabular.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 | |
read_transactions_tabular(filepath, *, sep='\t', user_col, item_col, rating_col=None, timestamp_col=None, header=None, skiprows=0, cols=None, engine='c', fallback_engine='python', stream=False, encode_ids=False, chunksize=100000, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a tabular data file (CSV, TSV, etc.) into a RawData object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the tabular data file. |
required |
sep
|
str
|
Delimiter to use (default: tab). |
'\t'
|
user_col
|
Union[str, int]
|
Column name or index for the user field (Required). |
required |
item_col
|
Union[str, int]
|
Column name or index for the item field (Required). |
required |
rating_col
|
Optional[Union[str, int]]
|
Column name or index for the rating field. |
None
|
timestamp_col
|
Optional[Union[str, int]]
|
Column name or index for the timestamp field. |
None
|
header
|
Union[int, List[int], str, None]
|
Row number(s) to use as the column names. Defaults to 'infer'. |
None
|
skiprows
|
Union[int, List[int]]
|
Line numbers to skip at the start of the file. |
0
|
cols
|
Optional[List[str]]
|
Explicit column names if the file has no header. Passed as |
None
|
engine
|
Optional[str]
|
Pandas CSV engine. |
'c'
|
fallback_engine
|
Optional[str]
|
Engine to try if the primary fails. |
'python'
|
stream
|
bool
|
If True, read in chunks to reduce memory. |
False
|
encode_ids
|
bool
|
If True, encode user/item to int ids using IncrementalEncoder. |
False
|
chunksize
|
int
|
Rows per chunk when streaming. |
100000
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
The loaded data. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/transactions/tabular.py
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 | |
read_transactions_json(filepath, *, user_col, item_col, rating_col=None, timestamp_col=None, lines=True, stream=False, encode_ids=False, chunksize=100000, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a JSON (or JSON Lines) file and returns it as a RawData object.
Arg names standardized to match read_tabular (user_col instead of user_field).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the JSON file. |
required |
user_col
|
str
|
JSON key corresponding to the user field (Required). |
required |
item_col
|
str
|
JSON key corresponding to the item field (Required). |
required |
rating_col
|
Optional[str]
|
JSON key corresponding to the rating field. |
None
|
timestamp_col
|
Optional[str]
|
JSON key corresponding to the timestamp field. |
None
|
lines
|
bool
|
If True, reads the file as a JSON object per line (JSONL). |
True
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
The loaded data. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/transactions/json.py
read_transactions_jsonl(filepath, *, user_col, item_col, rating_col=None, timestamp_col=None, stream=False, encode_ids=False, chunksize=100000, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a JSON Lines file and returns it as a RawData object.
Arg names standardized to match read_tabular (user_col instead of user_field).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the JSON file. |
required |
user_col
|
str
|
JSON key corresponding to the user field (Required). |
required |
item_col
|
str
|
JSON key corresponding to the item field (Required). |
required |
rating_col
|
Optional[str]
|
JSON key corresponding to the rating field. |
None
|
timestamp_col
|
Optional[str]
|
JSON key corresponding to the timestamp field. |
None
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
The loaded data. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/transactions/jsonl.py
read_transactions_blocks(filepath, *, block_by, event_layout, user_col='user', item_col='item', rating_col=None, timestamp_col=None, sep='\t', chunksize=None, dataset_name='Unknown Dataset', version_name='Unknown Version')
Reads a block text format into transactional RawData.
Block structure
- Header line per block: "
:" - Event lines:
- "id"
- "id,rating"
- "id,rating,timestamp"
The block header identifies either the item or the user depending on block_by. The event line id is the opposite entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the block text file. |
required |
block_by
|
Literal['item', 'user']
|
Whether blocks are grouped by "item" or by "user". |
required |
event_layout
|
Literal['id', 'id,rating', 'id,rating,timestamp']
|
Layout of event lines. |
required |
user_col
|
str
|
Output user column name. |
'user'
|
item_col
|
str
|
Output item column name. |
'item'
|
rating_col
|
Optional[str]
|
Output rating column name (required if layout includes rating). |
None
|
timestamp_col
|
Optional[str]
|
Output timestamp column name (required if layout includes timestamp). |
None
|
sep
|
str
|
Field separator used in event lines. |
'\t'
|
chunksize
|
Optional[int]
|
Optional number of rows per in-memory chunk before concatenation. |
None
|
dataset_name
|
str
|
Name to assign to the resulting DataRec dataset. |
'Unknown Dataset'
|
version_name
|
str
|
Version identifier to assign to the resulting DataRec dataset. |
'Unknown Version'
|
Returns:
| Name | Type | Description |
|---|---|---|
DataRec |
DataRec
|
A DataRec object containing all interactions row-by-row. (Returned via @annotate_datarec_output, which wraps the RawData.) |
Source code in datarec/io/readers/transactions/blocks.py
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 | |
write_sequences_json(data, filepath, *, item_col='item', rating_col='rating', timestamp_col='timestamp', include_rating=False, include_timestamp=False, ensure_ascii=False, indent=2, verbose=True)
Writes sequential interaction data to a JSON mapping in the form:
{
"<user_id>": [
{ "<item_col>": ..., "<rating_col>": ..., "<timestamp_col>": ... },
...
],
...
}
Notes:
- The input is expected to be transactional RawData (one row per interaction).
- User identifiers become JSON object keys (strings). Therefore, the output does
NOT contain a user field name (no user_col parameter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
item_col
|
str
|
Output key for the item field inside each event. |
'item'
|
rating_col
|
str
|
Output key for the rating field inside each event (only if include_rating=True). |
'rating'
|
timestamp_col
|
str
|
Output key for the timestamp field inside each event (only if include_timestamp=True). |
'timestamp'
|
include_rating
|
bool
|
Whether to include rating in each event. |
False
|
include_timestamp
|
bool
|
Whether to include timestamp in each event. |
False
|
ensure_ascii
|
bool
|
Whether to escape non-ascii characters. |
False
|
indent
|
Optional[int]
|
Pretty-print indentation level. |
2
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in datarec/io/writers/sequences/json.py
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 | |
write_sequences_json_array(data, filepath, *, user_col='user', item_col='item', rating_col='rating', timestamp_col='timestamp', sequence_key='sequence', include_rating=False, include_timestamp=False, ensure_ascii=False, indent=2, verbose=True)
Writes sequential interaction data to a JSON array format:
[
{
"<user_col>": <user_id>,
"<sequence_key>": [
{ "<item_col>": ..., "<rating_col>": ..., "<timestamp_col>": ... },
...
]
},
...
]
Notes: - The input is expected to be transactional RawData (one row per interaction). This writer groups interactions by user and produces a per-user sequence list. - Unlike the mapping format, user ids remain values (not JSON keys).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
user_col
|
str
|
Output key for the user field in each top-level object. |
'user'
|
item_col
|
str
|
Output key for the item field inside each event. |
'item'
|
rating_col
|
str
|
Output key for the rating field inside each event (only if include_rating=True). |
'rating'
|
timestamp_col
|
str
|
Output key for the timestamp field inside each event (only if include_timestamp=True). |
'timestamp'
|
sequence_key
|
str
|
Output key containing the list of events per user. |
'sequence'
|
include_rating
|
bool
|
Whether to include rating in each event. |
False
|
include_timestamp
|
bool
|
Whether to include timestamp in each event. |
False
|
ensure_ascii
|
bool
|
Whether to escape non-ascii characters. |
False
|
indent
|
Optional[int]
|
Pretty-print indentation level. |
2
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in datarec/io/writers/sequences/json.py
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 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 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
write_sequences_json_items(data, filepath, *, item_col='item', compact_items=True, ensure_ascii=False, indent=2, verbose=True)
Writes sequential interaction data to a JSON mapping in the form:
{
"<user_id>": [item_id, item_id, ...],
...
}
Notes:
- The input is expected to be transactional RawData (one row per interaction).
- User identifiers become JSON object keys (strings). Therefore, the output does
NOT contain a user field name (no user_col parameter).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
item_col
|
str
|
Output key name for the item field in RawData. |
'item'
|
compact_items
|
bool
|
Whether to keep item lists on a single line when indenting. |
True
|
ensure_ascii
|
bool
|
Whether to escape non-ascii characters. |
False
|
indent
|
Optional[int]
|
Pretty-print indentation level. |
2
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in datarec/io/writers/sequences/json.py
write_sequence_tabular_inline(data, filepath, *, user_col='user', sequence_col='sequence', sequence_sep=' ', include_timestamp=False, timestamp_col='timestamp', meta_cols=None, col_sep=',', header=True, index=False, decimal='.', engine=None, verbose=True)
Writes sequential interaction data to a tabular file where each row contains a single user and a serialized sequence in one column (inline format).
Output format (one sequence per row): user_col, sequence_col, [timestamp_col], [meta_cols...]
Notes:
- The input is expected to be transactional RawData (one row per (user, item)),
as produced by DataRec readers. This writer groups interactions by user and
serializes the per-user item list using sequence_sep.
- If include_timestamp=True, a per-user timestamp is derived by aggregating
RawData timestamps using a deterministic strategy (min timestamp).
- Metadata columns (meta_cols) are aggregated per user using a deterministic
strategy (first value).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
user_col
|
str
|
Output column name for user IDs. |
'user'
|
sequence_col
|
str
|
Output column name for the serialized sequence. |
'sequence'
|
sequence_sep
|
str
|
Separator used to serialize items in the sequence string. |
' '
|
include_timestamp
|
bool
|
Whether to include a per-user timestamp column. |
False
|
timestamp_col
|
str
|
Output column name for timestamp (used only if include_timestamp=True). |
'timestamp'
|
meta_cols
|
Optional[List[str]]
|
Additional metadata columns to include (if present in RawData). |
None
|
col_sep
|
str
|
Column delimiter for the output file. |
','
|
header
|
bool
|
Whether to write column names. |
True
|
index
|
bool
|
Whether to write the DataFrame index. |
False
|
decimal
|
str
|
Decimal separator passed to pandas. |
'.'
|
engine
|
Optional[str]
|
Optional pandas CSV engine hint. |
None
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in datarec/io/writers/sequences/tabular.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 | |
write_sequence_tabular_wide(data, filepath, *, user_col='user', item_col_prefix='item', col_sep='\t', header=False, index=False, decimal='.', verbose=True)
Writes sequential interaction data to a tabular-wide format, where each row corresponds to a user and items are spread across multiple columns.
Output example
user
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
user_col
|
str
|
Output column name for user IDs. |
'user'
|
item_col_prefix
|
str
|
Prefix for item columns (e.g., item_1, item_2, ...). |
'item'
|
col_sep
|
str
|
Column delimiter. |
'\t'
|
header
|
bool
|
Whether to write column names. |
False
|
index
|
bool
|
Whether to write the DataFrame index. |
False
|
decimal
|
str
|
Decimal separator. |
'.'
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in datarec/io/writers/sequences/tabular.py
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 | |
write_sequence_tabular_implicit(data, filepath, *, include_length_col=True, col_sep=' ', header=False, verbose=True)
Writes sequential interaction data to a tabular-implicit format, where each row represents a sequence and no explicit user identifier is written.
Output example (include_length_col=True, col_sep=" "): 3 10 20 30 2 11 42
Notes: - Each unique user in RawData is treated as a sequence instance. - The user identifier is NOT written to file. - If include_length_col=True, the first token is the sequence length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
include_length_col
|
bool
|
Whether to prepend the sequence length token. |
True
|
col_sep
|
str
|
Token separator used within each row (must match the reader's |
' '
|
header
|
bool
|
Whether to write a header row (generally False for this format). |
False
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in datarec/io/writers/sequences/tabular.py
write_transactions_tabular(data, filepath, *, sep='\t', header=True, decimal='.', include_user=True, include_item=True, include_rating=False, include_timestamp=False, user_col=None, item_col=None, rating_col=None, timestamp_col=None, index=False, engine=None, verbose=True)
Writes transactional interaction data to a tabular file (CSV/TSV/etc.).
one interaction per row
user, item, [rating], [timestamp]
This writer accepts either:
- RawData
- DataRec (converted via .to_rawdata())
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
sep
|
str
|
Column delimiter (e.g., '\t', ',', ';'). |
'\t'
|
header
|
bool
|
Whether to write column names. |
True
|
decimal
|
str
|
Decimal separator passed to pandas. |
'.'
|
include_user
|
bool
|
Whether to include the user column. |
True
|
include_item
|
bool
|
Whether to include the item column. |
True
|
include_rating
|
bool
|
Whether to include the rating column (if available). |
False
|
include_timestamp
|
bool
|
Whether to include the timestamp column (if available). |
False
|
user_col
|
Optional[str]
|
Output column name for user (optional rename). |
None
|
item_col
|
Optional[str]
|
Output column name for item (optional rename). |
None
|
rating_col
|
Optional[str]
|
Output column name for rating (optional rename). |
None
|
timestamp_col
|
Optional[str]
|
Output column name for timestamp (optional rename). |
None
|
index
|
bool
|
Whether to write the DataFrame index. |
False
|
engine
|
Optional[str]
|
Optional pandas CSV engine hint. |
None
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in datarec/io/writers/transactions/tabular.py
10 11 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 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 | |
write_transactions_json(data, filepath, *, user_col='user', item_col='item', rating_col='rating', timestamp_col='timestamp', include_user=True, include_item=True, include_rating=False, include_timestamp=False, indent=2, ensure_ascii=False, verbose=True)
Writes transactional interaction data as a single JSON array.
Source code in datarec/io/writers/transactions/json.py
write_transactions_jsonl(data, filepath, *, user_col='user', item_col='item', rating_col='rating', timestamp_col='timestamp', include_user=True, include_item=True, include_rating=False, include_timestamp=False, ensure_ascii=False, verbose=True)
Writes transactional interaction data as JSON Lines (one JSON object per line).
Source code in datarec/io/writers/transactions/jsonl.py
write_transactions_blocks(data, filepath, *, block_by, event_layout, include_user=True, include_item=True, include_rating=False, include_timestamp=False, sep='\t', verbose=True)
Writes transactional interaction data to a block text format:
<BLOCK_ID>:
id
id,rating
id,rating,timestamp
The block header identifies either the item or the user depending on block_by. The event line id is the opposite entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[RawData, DataRec]
|
RawData or DataRec instance. |
required |
filepath
|
str
|
Output path. |
required |
block_by
|
Literal['item', 'user']
|
Whether blocks are grouped by "item" or by "user". |
required |
event_layout
|
Literal['id', 'id,rating', 'id,rating,timestamp']
|
Layout of event lines. |
required |
include_user
|
bool
|
Must be True. |
True
|
include_item
|
bool
|
Must be True. |
True
|
include_rating
|
bool
|
Must be True if event_layout includes rating. |
False
|
include_timestamp
|
bool
|
Must be True if event_layout includes timestamp. |
False
|
sep
|
str
|
Field separator used in event lines. |
'\t'
|
verbose
|
bool
|
Whether to print a confirmation message. |
True
|
Source code in datarec/io/writers/transactions/blocks.py
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 | |
dataset_directory(dataset_name, must_exist=False)
Given the dataset name returns the dataset directory Args: dataset_name (str): name of the dataset must_exist (bool): flag for forcing to check if the folder exists
Returns:
| Type | Description |
|---|---|
str
|
the path of the directory containing the dataset data |
Source code in datarec/io/paths.py
dataset_version_directory(dataset_name, dataset_version, must_exist=False)
Given the dataset name and its version returns the dataset directory Args: dataset_name (str): name of the dataset version_name (str): version of the dataset must_exist (bool): flag for forcing to check if the folder exists
Returns:
| Type | Description |
|---|---|
str
|
the path of the directory containing the dataset data |
Source code in datarec/io/paths.py
dataset_raw_directory(dataset_name, dataset_version=None)
Given the dataset name returns the directory containing the raw data of the dataset Args: dataset_name (str): name of the dataset dataset_version (str): version of the dataset Returns: (str): the path of the directory containing the raw data of the dataset
Source code in datarec/io/paths.py
dataset_processed_directory(dataset_name)
Given the dataset name returns the directory containing the processed data of the dataset Args: dataset_name (str): name of the dataset
Returns:
| Type | Description |
|---|---|
str
|
the path of the directory containing the processed data of the dataset |
Source code in datarec/io/paths.py
dataset_filepath(dataset_name)
Given the dataset name returns the path of the dataset data Args: dataset_name (str): name of the dataset
Returns:
| Type | Description |
|---|---|
str
|
the path of the dataset data |
Source code in datarec/io/paths.py
registry_dataset_filepath(dataset_name)
Given the dataset name returns the path of the dataset configuration file in the dataset registry Args: dataset_name (str): name of the dataset Returns: (str): the path of the dataset configuration file
Source code in datarec/io/paths.py
registry_version_filepath(dataset_name, dataset_version)
Given the dataset name returns the path of the dataset configuration file in the dataset registry Args: dataset_name (str): name of the dataset dataset_version (str): version of the dataset Returns: (str): the path of the dataset configuration file
Source code in datarec/io/paths.py
registry_metrics_filepath(dataset_name, dataset_version)
Given dataset name and version, return the path of the precomputed metrics file in the registry metrics folder.
Source code in datarec/io/paths.py
pickle_version_filepath(dataset_name, dataset_version)
Given the dataset name and version returns the path of the pickled version of the dataset Args: dataset_name (str): name of the dataset dataset_version (str): version of the dataset Returns: (str): the path of the pickled version of the dataset
Source code in datarec/io/paths.py
Framework Interoperability
This section covers the tools used to export DataRec datasets into formats compatible with other popular recommender systems libraries.
FrameworkExporter
Exporter for converting RawData datasets to external recommender system frameworks.
Provides methods to format a RawData object according to
the expected schema of supported libraries (e.g., Cornac, RecBole).
Source code in datarec/io/frameworks/exporter.py
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 | |
__init__(output_path, user=True, item=True, rating=True, timestamp=False)
Initialize a FrameworkExporter object. Args: output_path (str): Path where to save the output file. user (bool): Whether to write the user information. If True, the user information will be written in the file. item (bool): Whether to write the item information. If True, the item information will be written in the file. rating (bool): Whether to write the rating information. If True, the rating information will be written in the file. timestamp (bool): Whether to write the timestamp information. If True, the timestamp information will be written in the file.
Source code in datarec/io/frameworks/exporter.py
to_clayrs(data)
Export to ClayRS format. Args: data (RawData): RawData object to convert to ClayRS format.
Source code in datarec/io/frameworks/exporter.py
to_cornac(data)
Export to Cornac format. Args: data (RawData): RawData object to convert to Cornac format.
Source code in datarec/io/frameworks/exporter.py
to_daisyrec(data)
Export to DaisyRec format. Args: data (RawData): RawData object to convert to DaisyRec format.
Source code in datarec/io/frameworks/exporter.py
to_lenskit(data)
Export to LensKit format. Args: data (RawData): RawData object to convert to LensKit format.
Source code in datarec/io/frameworks/exporter.py
to_recbole(data)
Export to RecBole format. Args: data (RawData): RawData object to convert to RecBole format.
Source code in datarec/io/frameworks/exporter.py
to_rechorus(train_data, test_data, val_data)
Export to Rechus format. Args: train_data (RawData): Training data as RawData object to convert to Rechus format. test_data (RawData): Test data as RawData object to convert to Rechus format. val_data (RawData): Validation data as RawData object to convert to Rechus format.
Source code in datarec/io/frameworks/exporter.py
to_recpack(data)
Export to RecPack format. Args: data (RawData): RawData object to convert to RecPack format.
Source code in datarec/io/frameworks/exporter.py
to_recommenders(data)
Export to Recommenders format. Args: data (RawData): RawData object to convert to Recommenders format.
Source code in datarec/io/frameworks/exporter.py
to_elliot(train_data, test_data, val_data)
Export to Elliot format. Args: train_data (DataRec): Training data as DataRec object to convert to Elliot format. test_data (DataRec): Test data as DataRec object to convert to Elliot format. val_data (DataRec): Validation data as DataRec object to convert to Elliot format.
Source code in datarec/io/frameworks/exporter.py
Framework
Base class for all framework exporters.
Source code in datarec/io/frameworks/manager.py
info_code()
info()
Print citation information for the framework including: paper name, DOI and bibtex citation. Print additional information such as: example code for integrating this framework with DataRec, repository URL and framework documentation URL. Returns:
Source code in datarec/io/frameworks/manager.py
ClayRS
ClayRS
Bases: Framework
ClayRS framework adapter.
Provide metadata, citation, and usage examples for ClayRS framework.
Source code in datarec/io/frameworks/clayrs/clayrs.py
__init__(timestamp, path)
Initialize ClayRS adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the ClayRS-compatible dataset is stored.
Source code in datarec/io/frameworks/clayrs/clayrs.py
info_code()
Provide the code to use in ClayRS to run experiments.
Source code in datarec/io/frameworks/clayrs/clayrs.py
Cornac
Cornac
Bases: Framework
Cornac framework adapter.
Provide metadata, citation, and usage examples for Cornac framework.
Source code in datarec/io/frameworks/cornac/cornac.py
__init__(timestamp, path)
Initialize Cornac adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the Cornac-compatible dataset is stored.
Source code in datarec/io/frameworks/cornac/cornac.py
info_code()
Provide the code to use in Cornac to run experiments.
Source code in datarec/io/frameworks/cornac/cornac.py
DaisyRec
DaisyRec
Bases: Framework
DaisyRec framework adapter.
Provide metadata, citation, and usage examples for DaisyRec framework.
Source code in datarec/io/frameworks/daisyrec/daisyrec.py
4 5 6 7 8 9 10 11 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 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 | |
__init__(timestamp, path)
Initialize DaisyRec adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the DaisyRec-compatible dataset is stored.
Source code in datarec/io/frameworks/daisyrec/daisyrec.py
info_code()
Provide the code to use in DaisyRec to run experiments.
Source code in datarec/io/frameworks/daisyrec/daisyrec.py
load_rate(src='ml-100k', prepro='origin', binary=True, pos_threshold=None, level='ui')
Load certain raw data. Args: src (str): Name of dataset. prepro (str): Way to pre-process raw data input, expect 'origin', f'{N}core', f'{N}filter', N is integer value. binary (boolean): Whether to transform rating to binary label as CTR or not as Regression. pos_threshold (float): If not None, treat rating larger than this threshold as positive sample. level (str): which level to do with f'{N}core' or f'{N}filter' operation (it only works when prepro contains 'core' or 'filter').
Returns:
| Type | Description |
|---|---|
Dataframe
|
Rating information with columns: user, item, rating, (options: timestamp). |
int
|
The number of users in the dataset. |
int
|
The number of items in the dataset. |
Source code in datarec/io/frameworks/daisyrec/loader.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 | |
get_ur(df)
Get user-rating pairs. Args: df (pd.DataFrame): Rating dataframe.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary which stores user-items interactions. |
Source code in datarec/io/frameworks/daisyrec/loader.py
get_ir(df)
Get item-rating pairs. Args: df (pd.DataFrame): Rating dataframe.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary which stores item-items interactions. |
Source code in datarec/io/frameworks/daisyrec/loader.py
build_feat_idx_dict(df, cat_cols=['user', 'item'], num_cols=[])
Encode feature mapping for FM. Args: df (pd.DataFrame): Feature dataframe. cat_cols (list): List of categorical column names. num_cols (list): List of numerical column names.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with index-feature column mapping information. |
int
|
The number of features. |
Source code in datarec/io/frameworks/daisyrec/loader.py
convert_npy_mat(user_num, item_num, df)
Convert pd.Dataframe to numpy matrix. Args: user_num(int): Number of users. item_num (int): Number of items. df (pd.DataFrame): Rating dataframe.
Returns:
| Type | Description |
|---|---|
array
|
Rating matrix. |
Source code in datarec/io/frameworks/daisyrec/loader.py
build_candidates_set(test_ur, train_ur, item_pool, candidates_num=1000)
Build candidate items for ranking. Args: test_ur (dict): Ground truth that represents the relationship of user and item in the test set. train_ur (dict): The relationship of user and item in the train set. item_pool (list or set): Set of all items. candidates_num (int): Number of candidates.:
Returns:
| Name | Type | Description |
|---|---|---|
test_ucands |
dict
|
Dictionary storing candidates for each user in test set. |
Source code in datarec/io/frameworks/daisyrec/loader.py
get_adj_mat(n_users, n_items)
Get adjacency matrix. Args: n_users (int): Number of users. n_items (int): Number of items.
Returns:
| Name | Type | Description |
|---|---|---|
adj_mat |
csr_matrix
|
Adjacency matrix. |
norm_adj_mat |
csr_matrix
|
Normalized adjacency matrix. |
mean_adj_mat |
csr_matrix
|
Mean adjacency matrix. |
Source code in datarec/io/frameworks/daisyrec/loader.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
Elliot
Elliot
Bases: Framework
Elliot framework adapter.
Provide metadata, citation, and usage examples for Elliot framework.
Source code in datarec/io/frameworks/elliot/elliot.py
6 7 8 9 10 11 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 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 | |
__init__(timestamp, path)
Initialize Elliot adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the Elliot-compatible dataset is stored.
Source code in datarec/io/frameworks/elliot/elliot.py
info_code()
Provide the code to use in Elliot to run experiments.
Source code in datarec/io/frameworks/elliot/elliot.py
LensKit
LensKit
Bases: Framework
LensKit framework adapter.
Provide metadata, citation, and usage examples for LensKit framework.
Source code in datarec/io/frameworks/lenskit/lenskit.py
__init__(timestamp, path)
Initialize LensKit adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the LensKit-compatible dataset is stored.
Source code in datarec/io/frameworks/lenskit/lenskit.py
info_code()
Provide the code to use in LensKit to run experiments.
Source code in datarec/io/frameworks/lenskit/lenskit.py
RecBole
RecBole
Bases: Framework
RecBole framework adapter.
Provide metadata, citation, and usage examples for RecBole framework.
Source code in datarec/io/frameworks/recbole/recbole.py
6 7 8 9 10 11 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 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 | |
__init__(timestamp, path)
Initialize RecBole adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the RecBole-compatible dataset is stored.
Source code in datarec/io/frameworks/recbole/recbole.py
info_code()
Provide the code to use in RecBole to run experiments.
Source code in datarec/io/frameworks/recbole/recbole.py
ReChorus
ReChorus
Bases: Framework
ReChorus framework adapter.
Provide metadata, citation, and usage examples for ReChorus framework.
Source code in datarec/io/frameworks/rechorus/rechorus.py
__init__(timestamp, path)
Initialize ReChorus adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the ReChorus-compatible dataset is stored.
Source code in datarec/io/frameworks/rechorus/rechorus.py
info_code()
Provide the code to use in RecBole to run experiments.
Source code in datarec/io/frameworks/rechorus/rechorus.py
Recommenders
Recommenders
Bases: Framework
Recommenders framework adapter.
Provide metadata, citation, and usage examples for Recommenders framework.
Source code in datarec/io/frameworks/recommenders/recommenders.py
__init__(timestamp, path)
Initialize Recommenders adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the Recommenders-compatible dataset is stored.
Source code in datarec/io/frameworks/recommenders/recommenders.py
info_code()
Provide the code to use in Recommenders to run experiments.
Source code in datarec/io/frameworks/recommenders/recommenders.py
RecPack
RecPack
Bases: Framework
RecPack framework adapter.
Provide metadata, citation, and usage examples for RecPack framework.
Source code in datarec/io/frameworks/recpack/recpack.py
__init__(timestamp, path)
Initialize RecPack adapter. Args: timestamp (bool): Whether timestamps are included. path (str): Path where the RecPack-compatible dataset is stored.
Source code in datarec/io/frameworks/recpack/recpack.py
info_code()
Provide the code to use in RecPack to run experiments.
Source code in datarec/io/frameworks/recpack/recpack.py
DataRec
Bases: Dataset
Base class for DataRec Datasets
Source code in datarec/io/frameworks/recpack/datarec.py
USER_IX = 'userId'
class-attribute
instance-attribute
Name of the column in the DataFrame that contains user identifiers.
ITEM_IX = 'itemId'
class-attribute
instance-attribute
Name of the column in the DataFrame that contains item identifiers.
TIMESTAMP_IX = 'timestamp'
class-attribute
instance-attribute
Name of the column in the DataFrame that contains time of interaction in seconds since epoch.
DEFAULT_FILENAME
property
Default filename that will be used if it is not specified by the user.