Config class
config.DatasetConfig
The main class for the configuration of:
- Train, validation, test sets (dates, sizes, validation approach).
- Application selection — either the standard closed-world setting (only known classes) or the open-world setting (known and unknown classes).
- Data transformations. See the transforms page for more information.
- Dataloader options like batch sizes, order of loading, or number of workers.
When initializing this class, pass a CesnetDataset
instance to be configured and the desired configuration. Available options are here.
Attributes:
Name | Type | Description |
---|---|---|
dataset |
InitVar[CesnetDataset]
|
The dataset instance to be configured. |
data_root |
str
|
Taken from the dataset instance. |
database_filename |
str
|
Taken from the dataset instance. |
database_path |
str
|
Taken from the dataset instance. |
servicemap_path |
str
|
Taken from the dataset instance. |
flowstats_features |
list[str]
|
Taken from |
flowstats_features_boolean |
list[str]
|
Taken from |
flowstats_features_phist |
list[str]
|
Taken from |
other_fields |
list[str]
|
Taken from |
sni_column |
list[str]
|
Database column with SNI domains, can be None for datasets without SNI domains. |
Configuration options
Attributes:
Name | Type | Description |
---|---|---|
need_train_set |
bool
|
Use to disable the train set. |
need_val_set |
bool
|
Use to disable the validation set. |
need_test_set |
bool
|
Use to disable the test set. |
train_period_name |
str
|
Name of the train period. See instructions. |
train_dates |
list[str]
|
Dates used for creating a train set. |
train_dates_weigths |
Optional[list[int]]
|
To use a non-uniform distribution of samples across train dates. |
val_approach |
ValidationApproach
|
How a validation set should be created. Either split train data into train and validation or have a separate validation period. |
train_val_split_fraction |
float
|
The fraction of validation samples when splitting from the train set. |
val_period_name |
str
|
Name of the validation period. See instructions. |
val_dates |
list[str]
|
Dates used for creating a validation set. |
test_period_name |
str
|
Name of the test period. See instructions. |
test_dates |
list[str]
|
Dates used for creating a test set. |
apps_selection |
AppSelection
|
How to select application classes. |
apps_selection_topx |
int
|
Take top X as known. |
apps_selection_background_unknown |
list[str]
|
Provide a list of background traffic classes to be used as unknown. |
apps_selection_fixed_known |
list[str]
|
Provide a list of manually selected known applications. |
apps_selection_fixed_unknown |
list[str]
|
Provide a list of manually selected unknown applications. |
disabled_apps |
list[str]
|
List of applications to be disabled and not used at all. |
min_train_samples_check |
MinTrainSamplesCheck
|
How to handle applications with not enough training samples. |
min_train_samples_per_app |
int
|
Defines the threshold for not enough. |
random_state |
int
|
Fix all random processes performed during dataset initialization. |
fold_id |
int
|
To perform N-fold cross-validation, set this to |
train_workers |
int
|
Number of workers for loading train data. |
test_workers |
int
|
Number of workers for loading test data. |
val_workers |
int
|
Number of workers for loading validation data. |
batch_size |
int
|
Number of samples per batch. |
test_batch_size |
int
|
Number of samples per batch for loading validation and test data. |
preload_val |
bool
|
Whether to dump the validation set with |
preload_test |
bool
|
Whether to dump the test set with |
train_size |
int | Literal['all']
|
Size of the train set. See instructions. |
val_known_size |
int | Literal['all']
|
Size of the validation set. See instructions. |
test_known_size |
int | Literal['all']
|
Size of the test set. See instructions. |
val_unknown_size |
int | Literal['all']
|
Size of the unknown classes validation set. Use for evaluation in the open-world setting. |
test_unknown_size |
int | Literal['all']
|
Size of the unknown classes test set. Use for evaluation in the open-world setting. |
train_dataloader_order |
DataLoaderOrder
|
Whether to load train data in sequential or random order. |
train_dataloader_seed |
Optional[int]
|
Seed for loading train data in random order. |
return_other_fields |
bool
|
Whether to return auxiliary fields, such as communicating hosts, flow times, and more fields extracted from the ClientHello message. |
return_tensors |
bool
|
Use for returning |
use_packet_histograms |
bool
|
Whether to use packet histogram features, if available in the dataset. |
use_tcp_features |
bool
|
Whether to use TCP features, if available in the dataset. |
use_push_flags |
bool
|
Whether to use push flags in packet sequences, if available in the dataset. |
fit_scalers_samples |
int | float
|
Used when scaling transformation is configured and requires fitting. Fraction of train samples used for fitting, if float. The absolute number of samples otherwise. |
ppi_transform |
Optional[Callable]
|
Transform function for PPI sequences. See the transforms page for more information. |
flowstats_transform |
Optional[Callable]
|
Transform function for flow statistics. See the transforms page for more information. |
flowstats_phist_transform |
Optional[Callable]
|
Transform function for packet histograms. See the transforms page for more information. |
How to configure train, validation, and test sets
There are three options for how to define train/validation/test dates.
- Choose a predefined time period (
train_period_name
,val_period_name
, ortest_period_name
) available indataset.time_periods
and leave the list of dates (train_dates
,val_dates
, ortest_dates
) empty. - Provide a list of dates and a name for the time period. The dates are checked against
dataset.available_dates
. - Do not specify anything and use the dataset's defaults
dataset.default_train_period_name
anddataset.default_test_period_name
.
There are two options for configuring sizes of train/validation/test sets.
- Select an appropriate dataset size (default is
S
) when creating theCesnetDataset
instance and leavetrain_size
,val_known_size
, andtest_known_size
with their defaultall
value. This will create train/validation/test sets with all samples available in the selected dataset size (of course, depending on the selected dates and validation approach). - Provide exact sizes in
train_size
,val_known_size
, andtest_known_size
. This will create train/validation/test sets of the given sizes by doing a random subset. This is especially useful when using theORIG
dataset size and want to control the size of experiments.
Tip
The default approach for creating a validation set is to randomly split the train data into train and validation. The second approach is to define separate validation dates. See ValidationApproach.
Source code in cesnet_datazoo\config.py
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 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
|
Functions
get_flowstats_features_len
get_flowstats_features_len() -> int
Gets the number of flow statistics features.
Source code in cesnet_datazoo\config.py
420 421 422 |
|
get_flowstats_feature_names_expanded
get_flowstats_feature_names_expanded(
shorter_names: bool = False,
) -> list[str]
Gets names of flow statistics features. Packet histograms are expanded into bin features.
Source code in cesnet_datazoo\config.py
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 |
|
get_ppi_feature_names
get_ppi_feature_names() -> list[str]
Gets the names of flattened PPI features.
Source code in cesnet_datazoo\config.py
458 459 460 461 462 463 464 465 |
|
get_ppi_channels
get_ppi_channels() -> list[int]
Gets the available features (channels) in PPI sequences.
Source code in cesnet_datazoo\config.py
467 468 469 470 471 472 |
|
get_feature_names
get_feature_names(
flatten_ppi: bool = False, shorter_names: bool = False
) -> list[str]
Gets feature names.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flatten_ppi |
bool
|
Whether to flatten PPI into individual feature names or keep one |
False
|
Source code in cesnet_datazoo\config.py
474 475 476 477 478 479 480 481 482 483 |
|
Enums for configuration
The following enums are used for dataset configuration.
config.ValidationApproach
The validation approach defines which samples should be used for creating a validation set.
class-attribute
instance-attribute
SPLIT_FROM_TRAIN = 'split-from-train'
Split train data into train and validation.
Scikit-learn train_test_split
is used to create a random stratified validation set. The fraction of validation samples is defined in train_val_split_fraction
.
class-attribute
instance-attribute
VALIDATION_DATES = 'validation-dates'
Use separate validation dates to create a validation set. Validation dates need to be specified in val_dates
, and the name of the validation period in val_period_name
.
config.AppSelection
Applications can be divided into known and unknown classes. To use a dataset in the standard closed-world setting, use ALL_KNOWN
to select all the applications as known.
Use TOPX_KNOWN
or BACKGROUND_UNKNOWN
for the open-world setting and evaluation of out-of-distribution or open-set recognition methods.
The FIXED
is for manual selection of known and unknown applications.
class-attribute
instance-attribute
ALL_KNOWN = 'all-known'
Use all applications as known.
class-attribute
instance-attribute
TOPX_KNOWN = 'topx-known'
Use the first X (apps_selection_topx
) most frequent (with the most samples) applications as known, and the rest as unknown.
Applications with the same provider are never separated, i.e., all applications of a given provider are either known or unknown.
class-attribute
instance-attribute
BACKGROUND_UNKNOWN = 'background-unknown'
Use the list of background traffic classes (apps_selection_background_unknown
) as unknown, and the rest as known.
class-attribute
instance-attribute
FIXED = 'fixed'
Manual application selection. Provide lists of known applications (apps_selection_fixed_known
) and unknown applications (apps_selection_fixed_unknown
).
config.MinTrainSamplesCheck
Depending on the selected train dates, there might be applications with not enough samples for training (what is not enough will depend on the selected classification model).
The threshold for the minimum number of samples can be set with min_train_samples_per_app
, and its default value is 100.
With the DISABLE_APPS
approach, these applications will be disabled and not used for training or testing.
With the WARN_AND_EXIT
approach, the script will print a warning and exit if applications with not enough samples are encountered.
To disable this check, set min_train_samples_per_app
to 0.
class-attribute
instance-attribute
WARN_AND_EXIT = 'warn-and-exit'
Warn and exit if there are not enough training samples for some applications. It is up to the user to manually add these applications to disabled_apps
.
class-attribute
instance-attribute
DISABLE_APPS = 'disable-apps'
Disable applications with not enough training samples.
config.DataLoaderOrder
Validation and test sets are always loaded in sequential order — sequential meaning in the order of dates and time.
However, for the train set, it is sometimes required to iterate it in random order (for example, for training a neural network).
Thus, use RANDOM
if your classification model requires it; SEQUENTIAL
otherwise.
This setting affects only train_dataloader. Dataframe get_train_df is always created in sequential order.
class-attribute
instance-attribute
RANDOM = 'random'
Iterate train data in random order.
class-attribute
instance-attribute
SEQUENTIAL = 'sequential'
Iterate train data in sequential (datetime) order.