time_series_dataloader
Bases: dataloader
A base class for time series data loading and processing.
This class provides methods for downloading, partitioning, normalizing, and loading time series data for machine learning tasks.
Attributes:
Name | Type | Description |
---|---|---|
data_profile |
dict
|
A dictionary containing metadata about the dataset, including URL information. |
x_len |
int
|
The number of time steps in the input data (X). |
y_len |
int
|
The number of time steps in the output data (y). |
xy_gap |
int, default = 1
|
The gap between the input and output time steps. |
name |
str, default = 'time_series_dataloader'
|
The name of the dataloader instance. |
time_granularity |
str, default = 'daily'
|
The granularity of the time series data (e.g., daily, hourly). |
target_attributes |
str, default = 'All'
|
The target attributes for prediction (e.g., Open, Close). |
coverage_year_range |
int, default = 1
|
The range of years covered by the dataset. |
instance_ids |
int or str or None, default = None
|
The IDs of specific instances to load. |
train_batch_size |
int, default = 64
|
The batch size for training data. |
test_batch_size |
int, default = 64
|
The batch size for testing data. |
Methods:
Name | Description |
---|---|
__init__ |
Initializes the time series dataloader with the given configuration. |
get_data_profile |
Returns the data profile of the dataset. |
get_name |
Returns the name of the dataloader instance. |
get_attribute_list |
Returns the list of target attributes available in the dataset. |
get_time_granularity_list |
Returns the list of supported time granularities for the dataset. |
download_data |
Downloads the raw data files from the specified URLs. |
load_raw |
Loads raw time series data from the specified directory. |
partition_data |
Partitions the data into input (X) and output (y) time steps. |
load |
Loads, processes, and partitions the time series data for training and testing. |
Source code in tinybig/data/time_series_dataloader.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 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 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 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 |
|
__init__(data_profile, x_len, y_len, xy_gap=1, name='time_series_dataloader', time_granularity='daily', target_attributes='All', coverage_year_range=1, instance_ids=None, train_batch_size=64, test_batch_size=64)
Initializes the time series dataloader with the specified configurations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_profile
|
dict
|
The dataset profile containing metadata and URLs. |
required |
x_len
|
int
|
The number of input time steps. |
required |
y_len
|
int
|
The number of output time steps. |
required |
xy_gap
|
int
|
The gap between input and output time steps. |
= 1
|
name
|
str
|
The name of the dataloader. |
= 'time_series_dataloader'
|
time_granularity
|
str
|
The granularity of the time series data (e.g., daily, weekly). |
= 'daily'
|
target_attributes
|
str
|
The attributes for prediction (e.g., Open, Close). |
= 'All'
|
coverage_year_range
|
int
|
The range of years to cover in the dataset. |
= 1
|
instance_ids
|
int, str, or None
|
Specific instance IDs to load. |
= None
|
train_batch_size
|
int
|
The batch size for training data. |
= 64
|
test_batch_size
|
int
|
The batch size for testing data. |
= 64
|
Source code in tinybig/data/time_series_dataloader.py
download_data(cache_dir, file_name, time_granularity)
Downloads raw time series data from specified URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_dir
|
str
|
The directory to save the downloaded data. |
required |
file_name
|
str
|
The name of the data file to download. |
required |
time_granularity
|
str
|
The granularity of the data (e.g., daily, weekly). |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If any required parameter is missing. |
Source code in tinybig/data/time_series_dataloader.py
get_attribute_list()
Returns the list of target attributes available in the dataset.
Returns:
Type | Description |
---|---|
list
|
The list of target attributes (e.g., Open, High, Close). |
Source code in tinybig/data/time_series_dataloader.py
get_data_profile()
Returns the data profile of the dataset.
Returns:
Type | Description |
---|---|
dict
|
The dataset profile containing metadata and URLs. |
get_name()
Returns the name of the dataloader.
Returns:
Type | Description |
---|---|
str
|
The name of the dataloader instance. |
get_time_granularity_list()
Returns the list of supported time granularities for the dataset.
Returns:
Type | Description |
---|---|
list
|
The list of time granularities (e.g., daily, weekly). |
Source code in tinybig/data/time_series_dataloader.py
load(cache_dir=None, time_granularity=None, target_attributes=None, coverage_year_range=None, instance_ids=None, train_percentage=0.8, normalize=True, normalization_mode='instance_time', device='cpu', *args, **kwargs)
Loads, processes, and partitions the time series data for training and testing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_dir
|
str
|
The directory to cache the data. |
None
|
time_granularity
|
str
|
The granularity of the time series data (e.g., daily, weekly). |
None
|
target_attributes
|
str
|
The target attributes for prediction. |
None
|
coverage_year_range
|
int
|
The range of years to cover in the dataset. |
None
|
instance_ids
|
int, str, or None
|
Specific instance IDs to load. |
None
|
train_percentage
|
float
|
The percentage of data to use for training. |
= 0.8
|
normalize
|
bool
|
Whether to normalize the time series data. |
= True
|
normalization_mode
|
str
|
The normalization mode (e.g., 'instance', 'time', 'global'). |
= 'instance_time'
|
device
|
str
|
The device to load the data onto (e.g., CPU or GPU). |
= 'cpu'
|
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing training and testing DataLoaders, and the loaded instance IDs. |
Raises:
Type | Description |
---|---|
ValueError
|
If invalid parameters are provided or the data cannot be loaded. |
Source code in tinybig/data/time_series_dataloader.py
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 323 324 325 326 327 328 329 330 331 332 333 334 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 |
|
load_raw(cache_dir, file_name, time_granularity, device='cpu')
Loads raw time series data from the specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_dir
|
str
|
The directory containing the data files. |
required |
file_name
|
str
|
The name of the data file to load. |
required |
time_granularity
|
str
|
The granularity of the data (e.g., daily, weekly). |
required |
device
|
str
|
The device to load the data onto (e.g., CPU or GPU). |
= 'cpu'
|
Returns:
Type | Description |
---|---|
tuple
|
A tuple containing instance IDs, timestamps, and the time series data as tensors. |
Raises:
Type | Description |
---|---|
ValueError
|
If any required parameter is missing. |
Source code in tinybig/data/time_series_dataloader.py
partition_data(data_batch, x_len, y_len, xy_gap)
Partitions the time series data into input (X) and output (y) sequences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_batch
|
Tensor
|
The raw time series data to partition. |
required |
x_len
|
int
|
The number of time steps in the input sequence. |
required |
y_len
|
int
|
The number of time steps in the output sequence. |
required |
xy_gap
|
int
|
The gap between the input and output sequences. |
required |
Returns:
Type | Description |
---|---|
tuple
|
A tuple containing arrays of input (X) and output (y) sequences. |
Raises:
Type | Description |
---|---|
ValueError
|
If the data batch size is insufficient for partitioning. |