Time-based config class
cesnet_tszoo.configs.time_based_config.TimeBasedConfig
Bases: TimeBasedHandler, DatasetConfig
This class is used for configuring the TimeBasedCesnetDataset.
Used to configure the following:
- Train, validation, test, all sets (time period, sizes, features, window size)
- Handling missing values (default values,
fillers) - Handling anomalies (
anomaly handlers) - Data transformation using
transformers - Applying custom handlers (
custom handlers) - Changing order of preprocesses
- Dataloader options (train/val/test/all/init workers, batch sizes)
- Plotting
Important Notes:
- Custom fillers must inherit from the
fillersbase class. - Fillers can carry over values from the train set to the validation and test sets. For example,
ForwardFillercan carry over values from previous sets. - Custom anomaly handlers must inherit from the
anomaly handlersbase class. - It is recommended to use the
transformersbase class, though this is not mandatory as long as it meets the required methods.- If transformers are already initialized and
create_transformer_per_time_seriesisTrueandpartial_fit_initialized_transformersisTruethen transformers must supportpartial_fit. - If
create_transformer_per_time_seriesisTrue, transformers must have afitmethod andtransform_withshould be a list of transformers. - If
create_transformer_per_time_seriesisFalse, transformers must supportpartial_fit. - Transformers must implement the
transformmethod. - The
fit/partial_fitandtransformmethods must accept an input of typenp.ndarraywith shape(times, features).
- If transformers are already initialized and
- Custom handlers must be derived from one of the built-in
custom handlerclasses train_time_period,val_time_period,test_time_periodcan overlap, but they should keep order oftrain_time_period<val_time_period<test_time_period
Source code in cesnet_tszoo\configs\time_based_config.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 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 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 | |
Configuration options
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ts_ids
|
list[int] | NDArray[int_] | float | int
|
Defines which time series IDs are used for train/val/test/all. Can be a list of IDs, or an integer/float to specify a random selection. An |
required |
train_time_period
|
tuple[datetime, datetime] | range | float | None
|
Defines the time period for training set. Can be a range of time IDs or a tuple of datetime objects. Float value is equivalent to percentage of available times with offseted position from previous used set. |
None
|
val_time_period
|
tuple[datetime, datetime] | range | float | None
|
Defines the time period for validation set. Can be a range of time IDs or a tuple of datetime objects. Float value is equivalent to percentage of available times with offseted position from previous used set. |
None
|
test_time_period
|
tuple[datetime, datetime] | range | float | None
|
Defines the time period for test set. Can be a range of time IDs or a tuple of datetime objects. |
None
|
features_to_take
|
list[str] | Literal['all']
|
Defines which features are used. |
'all'
|
default_values
|
list[Number] | NDArray[number] | dict[str, Number] | Number | Literal['default'] | None
|
Default values for missing data, applied before fillers. Can set one value for all features or specify for each feature. |
'default'
|
sliding_window_size
|
int | None
|
Number of times in one window. Impacts dataloader behavior. Batch sizes affects how much data will be cached for creating windows. |
None
|
sliding_window_prediction_size
|
int | None
|
Number of times to predict from sliding_window_size. Impacts dataloader behavior. Batch sizes affects how much data will be cached for creating windows. |
None
|
sliding_window_step
|
int
|
Number of times to move by after each window. |
1
|
set_shared_size
|
float | int
|
How much times should time periods share. Order of sharing is training set < validation set < test set. Only in effect if sets share less values than set_shared_size. Use float value for percentage of total times or int for count. |
0
|
train_batch_size
|
int
|
Batch size for the train dataloader. Affects number of returned times in one batch. |
32
|
val_batch_size
|
int
|
Batch size for the validation dataloader. Affects number of returned times in one batch. |
64
|
test_batch_size
|
int
|
Batch size for the test dataloader. Affects number of returned times in one batch. |
128
|
all_batch_size
|
int
|
Batch size for the all dataloader. Affects number of returned times in one batch. |
128
|
preprocess_order
|
list[str, type]
|
Defines in which order preprocesses are used. Also can add to order a type of |
['handling_anomalies', 'filling_gaps', 'transforming']
|
fill_missing_with
|
type | FillerType | Literal['mean_filler', 'forward_filler', 'linear_interpolation_filler'] | None
|
Defines how to fill missing values in the dataset. Can pass enum |
None
|
transform_with
|
type | list[Transformer] | ndarray[Transformer] | TransformerType | Transformer | Literal['min_max_scaler', 'standard_scaler', 'max_abs_scaler', 'log_transformer', 'robust_scaler', 'power_transformer', 'quantile_transformer', 'l2_normalizer'] | None
|
Defines the transformer used to transform the dataset. Can pass enum |
None
|
handle_anomalies_with
|
type | AnomalyHandlerType | Literal['z-score', 'interquartile_range'] | None
|
Defines the anomaly handler for handling anomalies in the train set. Can pass enum |
None
|
create_transformer_per_time_series
|
bool
|
If |
True
|
partial_fit_initialized_transformers
|
bool
|
If |
False
|
include_time
|
bool
|
If |
True
|
include_ts_id
|
bool
|
If |
True
|
time_format
|
TimeFormat | Literal['id_time', 'datetime', 'unix_time', 'shifted_unix_time']
|
Format for the returned time data. When using TimeFormat.DATETIME, time will be returned as separate list along rest of the values. |
ID_TIME
|
train_workers
|
int
|
Number of workers for loading training data. |
4
|
val_workers
|
int
|
Number of workers for loading validation data. |
3
|
test_workers
|
int
|
Number of workers for loading test data. |
2
|
all_workers
|
int
|
Number of workers for loading all data. |
4
|
init_workers
|
int
|
Number of workers for initial dataset processing during configuration. |
4
|
nan_threshold
|
float
|
Maximum allowable percentage of missing data. Time series exceeding this threshold are excluded. Time series over the threshold will not be used. Used for |
1.0
|
random_state
|
int | None
|
Fixes randomness for reproducibility during configuration and dataset initialization. |
None
|
Config attributes
Attributes:
| Name | Type | Description |
|---|---|---|
used_train_workers |
Optional[int]
|
Tracks the number of train workers in use. Helps determine if the train dataloader should be recreated based on worker changes. |
used_val_workers |
Optional[int]
|
Tracks the number of validation workers in use. Helps determine if the validation dataloader should be recreated based on worker changes. |
used_test_workers |
Optional[int]
|
Tracks the number of test workers in use. Helps determine if the test dataloader should be recreated based on worker changes. |
used_all_workers |
Optional[int]
|
Tracks the total number of all workers in use. Helps determine if the all dataloader should be recreated based on worker changes. |
uses_all_time_period |
bool
|
Whether all time period set should be used. |
import_identifier |
Optional[str]
|
Tracks the name of the config upon import. None if not imported. |
filler_factory |
FillerFactory
|
Represents factory used to create passed Filler type. |
anomaly_handler_factory |
AnomalyHandlerFactory
|
Represents factory used to create passed Anomaly Handler type. |
transformer_factory |
TransformerFactory
|
Represents factory used to create passed Transformer type. |
can_fit_fillers |
bool
|
Whether fillers in this config, can be fitted. |
logger |
Logger
|
Logger for displaying information. |
display_train_time_period |
Optional[range]
|
Used to display the configured value of |
display_val_time_period |
Optional[range]
|
Used to display the configured value of |
display_test_time_period |
Optional[range]
|
Used to display the configured value of |
display_all_time_period |
Optional[range]
|
Used to display the configured value of |
all_time_period |
Optional[ndarray]
|
If no specific sets (train/val/test) are provided, all time IDs are used. When any set is defined, only the time IDs in defined sets are used. |
ts_row_ranges |
Optional[ndarray]
|
Initialized when |
aggregation |
Optional[AgreggationType]
|
The aggregation period used for the data. |
source_type |
Optional[SourceType]
|
The source type of the data. |
database_name |
Optional[str]
|
Specifies which database this config applies to. |
features_to_take_without_ids |
Optional[ndarray]
|
Features to be returned, excluding time or time series IDs. |
indices_of_features_to_take_no_ids |
Optional[ndarray]
|
Indices of non-ID features in |
ts_id_name |
Optional[str]
|
Name of the time series ID, dependent on |
used_singular_train_time_series |
Optional[int]
|
Currently used singular train set time series for dataloader. |
used_singular_val_time_series |
Optional[int]
|
Currently used singular validation set time series for dataloader. |
used_singular_test_time_series |
Optional[int]
|
Currently used singular test set time series for dataloader. |
used_singular_all_time_series |
Optional[int]
|
Currently used singular all set time series for dataloader. |
train_preprocess_order |
list[PreprocessNote]
|
All preprocesses used for train set. |
val_preprocess_order |
list[PreprocessNote]
|
All preprocesses used for val set. |
test_preprocess_order |
list[PreprocessNote]
|
All preprocesses used for test set. |
all_preprocess_order |
list[PreprocessNote]
|
All preprocesses used for all set. |
is_initialized |
bool
|
Flag indicating if the configuration has already been initialized. If true, config initialization will be skipped. |
version |
str
|
Version of cesnet-tszoo this config was made in. |
export_update_needed |
bool
|
Whether config was updated to newer version and should be exported. |
ts_ids |
ndarray
|
Defines which time series IDs are used for train/val/test/all. Can be a list of IDs, or an integer/float to specify a random selection. An |
train_time_period |
Optional[ndarray]
|
Defines the time period for training set. Can be a range of time IDs or a tuple of datetime objects. Float value is equivalent to percentage of available times with offseted position from previous used set. |
val_time_period |
Optional[ndarray]
|
Defines the time period for validation set. Can be a range of time IDs or a tuple of datetime objects. Float value is equivalent to percentage of available times with offseted position from previous used set. |
test_time_period |
Optional[ndarray]
|
Defines the time period for test set. Can be a range of time IDs or a tuple of datetime objects. |
features_to_take |
list[str]
|
Defines which features are used. |
default_values |
ndarray
|
Default values for missing data, applied before fillers. Can set one value for all features or specify for each feature. |
sliding_window_size |
Optional[int]
|
Number of times in one window. Impacts dataloader behavior. Batch sizes affects how much data will be cached for creating windows. |
sliding_window_prediction_size |
Optional[int]
|
Number of times to predict from sliding_window_size. Impacts dataloader behavior. Batch sizes affects how much data will be cached for creating windows. |
sliding_window_step |
int
|
Number of times to move by after each window. |
set_shared_size |
int | float
|
How much times should time periods share. Order of sharing is training set < validation set < test set. Only in effect if sets share less values than set_shared_size. Use float value for percentage of total times or int for count. |
train_batch_size |
int
|
Batch size for the train dataloader. Affects number of returned times in one batch. |
val_batch_size |
int
|
Batch size for the validation dataloader. Affects number of returned times in one batch. |
test_batch_size |
int
|
Batch size for the test dataloader. Affects number of returned times in one batch. |
all_batch_size |
int
|
Batch size for the all dataloader. Affects number of returned times in one batch. |
preprocess_order |
list[PreprocessType]
|
Defines in which order preprocesses are used. Also can add to order a type of |
create_transformer_per_time_series |
bool
|
If |
partial_fit_initialized_transformers |
bool
|
If |
include_time |
bool
|
If |
include_ts_id |
bool
|
If |
time_format |
TimeFormat
|
Format for the returned time data. When using TimeFormat.DATETIME, time will be returned as separate list along rest of the values. |
train_workers |
int
|
Number of workers for loading training data. |
val_workers |
int
|
Number of workers for loading validation data. |
test_workers |
int
|
Number of workers for loading test data. |
all_workers |
int
|
Number of workers for loading all data. |
init_workers |
int
|
Number of workers for initial dataset processing during configuration. |
nan_threshold |
float
|
Maximum allowable percentage of missing data. Time series exceeding this threshold are excluded. Time series over the threshold will not be used. Used for |
random_state |
Optional[int]
|
Fixes randomness for reproducibility during configuration and dataset initialization. |