Plots
The plots module contains the methods used to generate the plots showed in the paper.
bar_plot(dataset, global_importances_file, filetype='npz', plot_path=os.getcwd(), f=6, save_image=True, show_plot=True, model='EIF+', interpretation='EXIFFI+', scenario=1)
Compute the Global Importance Bar Plot starting from the Global Feature Importance vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
Type[Dataset]
|
Input dataset |
required |
global_importances_file |
str
|
The path to the file containing the global importances. |
required |
filetype |
str
|
The file type of the global importances file. Defaults to "npz". |
'npz'
|
plot_path |
str
|
The path where the plot will be saved. Defaults to os.getcwd(). |
getcwd()
|
f |
int
|
The number of ranks to be displayed in the plot. Defaults to 6. |
6
|
save_image |
A boolean indicating whether the plot should be saved. Defaults to True. |
True
|
|
show_plot |
A boolean indicating whether the plot should be displayed. Defaults to True. |
True
|
|
model |
str
|
The AD model on which the importances should be computed. Defaults to 'EIF+'. |
'EIF+'
|
interpretation |
str
|
The interpretation model used. Defaults to 'EXIFFI+'. |
'EXIFFI+'
|
scenario |
int
|
The scenario number. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[figure, axes, DataFrame]
|
The figure, the axes and the bars dataframe. |
Source code in utils_reboot/plots.py
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 | |
get_contamination_comparison(model1, model2, dataset_name, path=os.getcwd())
Obtain the difference in precision between two models for different contamination values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model1 |
str
|
The first model name. |
required |
model2 |
str
|
The second model name. |
required |
dataset_name |
str
|
The dataset name. |
required |
path |
str
|
Starting path to retrieve the path where the precisions of the two models are stored. Defaults to os.getcwd(). |
getcwd()
|
Source code in utils_reboot/plots.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
get_vals(model, dataset_names, type='predict')
Obtain statistics on the execution time of a model for different datasets. These values will be used in the plot_time_scaling method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model |
str
|
The model name. |
required |
dataset_names |
List[str]
|
The list of dataset names. |
required |
type |
str
|
The type of execution time. Defaults to 'predict'. |
'predict'
|
Returns:
| Type | Description |
|---|---|
tuple[List, List, List]
|
The median, 5th percentile and 95th percentile values of the execution time. |
Source code in utils_reboot/plots.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 | |
importance_map(dataset, model, resolution=30, path_plot=os.getcwd(), save_plot=True, show_plot=False, factor=3, feats_plot=(0, 1), col_names=None, isdiffi=False, scenario=2, interpretation='EXIFFI+')
Produce the Local Feature Importance Scoremap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
Type[Dataset]
|
Input dataset |
required |
model |
Type[ExtendedIsolationForest]
|
The AD model. |
required |
resolution |
Optional[int]
|
The resolution of the plot. Defaults to 30. |
30
|
path_plot |
Optional[str]
|
The path where the plot will be saved. Defaults to os.getcwd(). |
getcwd()
|
save_plot |
Optional[bool]
|
A boolean indicating whether the plot should be saved. Defaults to True. |
True
|
show_plot |
Optional[bool]
|
A boolean indicating whether the plot should be displayed. Defaults to False. |
False
|
factor |
Optional[int]
|
The factor by which the min and max values of the features are extended. Defaults to 3. |
3
|
feats_plot |
Optional[tuple]
|
The features to be plotted. Defaults to (0,1). |
(0, 1)
|
col_names |
List[str]
|
The names of the features. Defaults to None. |
None
|
isdiffi |
Optional[bool]
|
A boolean indicating whether the local-DIFFI method should be used to compute the importance values. Defaults to False. |
False
|
scenario |
Optional[int]
|
The scenario number. Defaults to 2. |
2
|
interpretation |
Optional[str]
|
Name of the interpretation model used. Defaults to "EXIFFI+". |
'EXIFFI+'
|
Returns:
| Type | Description |
|---|---|
None
|
The function saves the plot in the specified path and displays it if the show_plot parameter is set to True. |
Source code in utils_reboot/plots.py
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 | |
plot_ablation(eta_list, avg_prec, EIF_value, dataset_name, plot_path=os.getcwd(), show_plot=False, save_plot=True, change_ylim=False)
Obtain the plot of the Average precision values against different values of the era parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eta_list |
List[float]
|
The list of eta values. |
required |
avg_prec |
List[ndarray]
|
The list of average precision values. |
required |
EIF_value |
float
|
The average precision value of the EIF model. |
required |
dataset_name |
str
|
The dataset name. |
required |
plot_path |
str
|
The path where the plot will be saved. Defaults to os.getcwd(). |
getcwd()
|
show_plot |
bool
|
A boolean indicating whether the plot should be displayed. Defaults to False. |
False
|
save_plot |
bool
|
A boolean indicating whether the plot should be saved. Defaults to True. |
True
|
change_ylim |
bool
|
A boolean indicating whether the y axis limits should be changed. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
tuple[figure, axes]
|
The figure and axes objects used to create the plot. |
Source code in utils_reboot/plots.py
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 | |
plot_feature_selection(precision_file, plot_path, precision_file_random=None, color=0, model=None, eval_model='EIF+', interpretation=None, scenario=2, save_image=True, plot_image=False, box_loc=None, change_box_loc=0.9, rotation=False, change_ylim=False)
Obtain the feature selection plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precision_file |
str
|
The path to the file containing the precision values. |
required |
plot_path |
str
|
The path where the plot will be saved. |
required |
precision_file_random |
Optional[str]
|
The path to the file containing precision values computed with the random Feature Selection approach. Defaults to None. |
None
|
color |
int
|
The color of the plot. Defaults to 0. |
0
|
model |
Optional[str]
|
Name of the AD model. Defaults to None. |
None
|
eval_model |
Optional[str]
|
Name of the evaluation model. Defaults to 'EIF+'. |
'EIF+'
|
interpretation |
Optional[str]
|
Name of the interpretation model used. Defaults to None. |
None
|
scenario |
Optional[int]
|
The scenario number. Defaults to 2. |
2
|
save_image |
bool
|
A boolean indicating whether the plot should be saved. Defaults to True. |
True
|
plot_image |
bool
|
A boolean indicating whether the plot should be displayed. Defaults to False. |
False
|
box_loc |
tuple
|
The location of the text box containing the Area under the curve of Feature Selection value. Defaults to None. |
None
|
change_box_loc |
float
|
Change the y axis value of the text box location containing the Area under the curve of Feature Selection value. Defaults to 0.9. |
0.9
|
rotation |
bool
|
A boolean indicating whether the x ticks should be rotated by 45 degrees. Defaults to False. |
False
|
change_ylim |
bool
|
A boolean indicating whether the y axis limits should be changed (from 1 to 1.1). Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
The function saves the plot in the specified path and displays it if the plot_image parameter is set to True. |
Source code in utils_reboot/plots.py
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 | |
plot_precision_over_contamination(precisions, dataset_name, model_name, plot_path, contamination=np.linspace(0.0, 0.1, 10), save_image=True, plot_image=False, ylim=(0, 1))
Obtain the precision over contamination plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precisions |
ndarray
|
The precision values for different contamination values, obtained from the contamination_in_training_precision_evaluation method. |
required |
dataset_name |
str
|
The dataset name. |
required |
model_name |
str
|
The model name. |
required |
plot_path |
str
|
The path where the plot will be saved. |
required |
contamination |
ndarray
|
The contamination values. Defaults to np.linspace(0.0,0.1,10). |
linspace(0.0, 0.1, 10)
|
save_image |
bool
|
A boolean indicating whether the plot should be saved. Defaults to True. |
True
|
plot_image |
bool
|
A boolean indicating whether the plot should be displayed. Defaults to False. |
False
|
ylim |
tuple
|
The y axis limits. Defaults to (0,1). |
(0, 1)
|
Returns:
| Type | Description |
|---|---|
None
|
The function saves the plot in the specified path and displays it if the plot_image parameter is set to True. |
Source code in utils_reboot/plots.py
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 | |
plot_time_scaling(model_names, dataset_names, data_path, type='predict', plot_type='samples', plot_path=os.getcwd(), show_plot=True, save_plot=True)
Obtain the time scaling plot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_names |
List[str]
|
The list of model names. |
required |
dataset_names |
List[str]
|
The list of dataset names. |
required |
data_path |
str
|
The path to the datasets. |
required |
type |
str
|
The type of execution time, accepted values are: ['fit','predict','importances'] Defaults to 'predict'. |
'predict'
|
plot_type |
str
|
The type of plot, accepted values are ['samples','features']. Defaults to 'samples'. |
'samples'
|
plot_path |
str
|
The path where the plot will be saved. Defaults to os.getcwd(). |
getcwd()
|
show_plot |
bool
|
A boolean indicating whether the plot should be displayed. Defaults to True. |
True
|
save_plot |
bool
|
A boolean indicating whether the plot should be saved. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
tuple[figure, axes]
|
The figure and axes objects used to create the plot. |
Source code in utils_reboot/plots.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
score_plot(dataset, global_importances_file, plot_path=os.getcwd(), save_image=True, show_plot=True, model='EIF+', interpretation='EXIFFI', scenario=1)
Obtain the Global Feature Importance Score Plot starting from the Global Feature Importance vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
Type[Dataset]
|
Input dataset |
required |
global_importances_file |
str
|
The path to the file containing the global importances. |
required |
plot_path |
str
|
The path where the plot will be saved. Defaults to os.getcwd(). |
getcwd()
|
save_image |
A boolean indicating whether the plot should be saved. Defaults to True. |
True
|
|
show_plot |
A boolean indicating whether the plot should be displayed. Defaults to True. |
True
|
|
model |
str
|
The AD model on which the importances should be computed. Defaults to 'EIF+'. |
'EIF+'
|
interpretation |
str
|
The interpretation model used. Defaults to 'EXIFFI'. |
'EXIFFI'
|
scenario |
The scenario number. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
tuple[axes, axes]
|
The two axes objects used to create the plot. |
Source code in utils_reboot/plots.py
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 | |