Utils
This section contains the documentation for the utils module. This module collects a series of utility functions that are used mainly for the experiments.
AutoEncoder
Bases: AutoEncoder
Wrapper of pyod.models.auto_encoder.AutoEncoder
Source code in utils_reboot/utils.py
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 | |
__init__(**kwargs)
Constructor of the class AutoEncoder which uses the constructor of the parent class AutoEncoder from pyod.models.auto_encoder module.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Add the name attribute to the class. |
Source code in utils_reboot/utils.py
115 116 117 118 119 120 121 122 123 124 125 | |
predict(X)
Overwrite the predict method of the parent class AutoEncoder from pyod.models.auto_encoder module to obtain the
Anomaly Scores instead of the class labels (i.e. inliers and outliers)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X |
array
|
Input dataset |
required |
Returns:
| Type | Description |
|---|---|
array
|
Anomaly Scores |
Source code in utils_reboot/utils.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
DIF
Bases: DIF
Wrapper of pyod.models.dif.DIF
Source code in utils_reboot/utils.py
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 | |
__init__(**kwargs)
Constructor of the class DIF which uses the constructor of the parent class DIF from pyod.models.dif module.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Add the name attribute to the class. |
Source code in utils_reboot/utils.py
61 62 63 64 65 66 67 68 69 70 | |
predict(X)
Overwrite the predict method of the parent class DIF from pyod.models.dif module to obtain the
Anomaly Scores instead of the class labels (i.e. inliers and outliers)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X |
array
|
Input dataset |
required |
Returns:
| Type | Description |
|---|---|
array
|
Anomaly Scores |
Source code in utils_reboot/utils.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
sklearn_IsolationForest
Bases: IsolationForest
Wrapper of sklearn.ensemble.IsolationForest
Source code in utils_reboot/utils.py
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 | |
__init__(**kwargs)
Constructor of the class sklearn_IsolationForest which uses the constructor of the parent class IsolationForest from sklearn.ensemble module.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Add the name attribute to the class. |
Source code in utils_reboot/utils.py
28 29 30 31 32 33 34 35 36 37 | |
predict(X)
Overwrite the predict method of the parent class IsolationForest from sklearn.ensemble module to obtain the
Anomaly Scores instead of the class labels (i.e. inliers and outliers)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X |
array
|
Input dataset |
required |
Returns:
| Type | Description |
|---|---|
array
|
Anomaly Scores |
Source code in utils_reboot/utils.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
get_feature_indexes(dataset, f1, f2)
Function to get the indexes of two features in the dataset given the feature names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
Type[Dataset]
|
Dataset |
required |
f1 |
Union[str, int]
|
Name of the first feature |
required |
f2 |
Union[str, int]
|
Name of the second feature |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Indexes of the two features in the dataset |
Source code in utils_reboot/utils.py
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 | |
get_most_recent_file(directory_path, filetype='pickle')
Function to get the most recent file (i.e. last modified file) in a directory path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory_path |
str
|
Directory path where the files are stored |
required |
filetype |
str
|
Type of the file (i.e. |
'pickle'
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the most recent file in the directory path |
Source code in utils_reboot/utils.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
open_element(file_path, filetype='pickle')
Function to open an element from a file (i.e. npz or pickle file) in the specified directory path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path |
str
|
Path to the file |
required |
filetype |
str
|
Type of the file (i.e. |
'pickle'
|
Returns:
| Type | Description |
|---|---|
Union[array, list, DataFrame, Type[Precisions], Type[NewPrecisions], Type[Precisions_random]]
|
Element stored in the file |
Source code in utils_reboot/utils.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
save_element(element, directory_path, filename='', filetype='pickle')
Function to save an element produced by an experiment in a file (i.e. npz or pickle file) in the specified directory path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element |
Union[array, list, DataFrame, Type[Precisions], Type[NewPrecisions], Type[Precisions_random]]
|
Element to be saved |
required |
directory_path |
str
|
Directory path where the file will be saved |
required |
filename |
str
|
Name of the file |
''
|
filetype |
str
|
Type of the file (i.e. |
'pickle'
|
Returns:
| Type | Description |
|---|---|
None
|
The method saves element and does not return any value |
Source code in utils_reboot/utils.py
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 | |
save_fs_prec(precs, path)
Function to save the feature selection precisions in a file (i.e. pickle file) in the specified directory path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precs |
namedtuple
|
Feature selection precisions |
required |
path |
str
|
Directory path where the file will be saved |
required |
Returns:
| Type | Description |
|---|---|
None
|
The method saves the feature selection precisions and does not return any value |
Source code in utils_reboot/utils.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
save_fs_prec_random(precs, path)
Function to save the feature selection precisions for random features in a file (i.e. pickle file) in the specified directory path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precs |
namedtuple
|
Feature selection precisions for random features |
required |
path |
str
|
Directory path where the file will be saved |
required |
Returns:
| Type | Description |
|---|---|
None
|
The method saves the feature selection precisions for random features and does not return any value |
Source code in utils_reboot/utils.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
select_pre_process()
Function to select the pre-processing of the dataset asking the user to input the pre-processing number.
This method was specifically designed to construct the tutorial.ipynb notebook for the documentation.
Returns:
| Type | Description |
|---|---|
bool
|
Boolean value to indicate whether the dataset should be pre-processed or not |
bool
|
(i.e. 1 to pre-process the dataset and 2 otherwise) |
Source code in utils_reboot/utils.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
select_pre_process_scenario(dataset)
Combine the selection of the pre-processing of the dataset and the scenario for the experiment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset |
Type[Dataset]
|
Dataset to be used in the experiment |
required |
Returns:
| Type | Description |
|---|---|
int
|
The selected scenario number (i.e. 1 for Scenario 1 and 2 for Scenario 2) |
Source code in utils_reboot/utils.py
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 | |
select_scenario()
Function to select the scenario for the experiment (i.e. Scenario 1 or Scenario 2) asking the user to input the scenario number.
This method was specifically designed to construct the tutorial.ipynb notebook for the documentation.
Returns:
| Type | Description |
|---|---|
int
|
The selected scenario number (i.e. 1 for Scenario 1 and 2 for Scenario 2) |
Source code in utils_reboot/utils.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |