Python library ANODI for Time Series Anomaly Detection
Project description
ANODI
This is the Python library ANODI for Time Series Anomaly Detection. It offers easy access to algorithms and benchmark data.
Short Description
- the core of the ANODI library is the algorithm class (
anodilib.algorithm
) that wrapps an algorithm and the data that the algorithm should be fit on. It has - for example - the following attributes:self.X_train_df, self.Y_train_df, self.X_test_df, self.Y_test_df
: Dataframes for train and test data and labelstrain_dls, test_dls
: Dataloaders (fastAI Usage) for train and test datalearner
: The Learner object for fastAI- most of the algorithms have additional attributes for window_length, stride and batch_size
- the data and some meta arguments are set up as a
DatasetSpecification
in thedata
module and given as argument to thealgorithm
object.- If not overriden by another test-DatasetSpecification in the
predict
function, the given data behind des DatasetSpecification is automatically split into the Dataframes and Dataloaders from above using the parametertest_fraction
- If not overriden by another test-DatasetSpecification in the
- ANODI offers the following modules:
algorithm
,data
,metrics
,model
(containing the underlying pytorch models),visualization
Example Usage
- Example Usage of IsolationForest Algorithm on the ECG200_TRAIN Dataset:
from anodilib.algorithm.IsolationForest import IsolationForest as IF
from anodilib.data.DatasetSpecification import ECG200_TRAIN
alg = IF(dataset_specification=ECG200_TRAIN, contamination="auto", test_fraction=0.2)
alg.fit()
alg.predict()
anoms = alg.getAnomalies()
print(anoms)
- Example Usage of ModifiedLSTM Algorithm on the ECG200_TRAIN Dataset using c_f1_score Metric:
from anodilib.algorithm.ModifiedLSTM import ModifiedLSTM
from anodilib.data.DatasetSpecification import ECG200_TRAIN
from metrics.cmetrics import c_f1_score
import numpy as np
alg = ModifiedLSTM(dataset_specification=ECG200_TRAIN, batch_size=28,window_len=4, stride=1)
alg.fit(epoch_num=50, learning_rate="lr_find",learning_rate_iteration=200)
alg.fit(epoch_num=50, learning_rate="lr_find",learning_rate_iteration=200)
alg.fit(epoch_num=50, learning_rate="lr_find",learning_rate_iteration=200)
alg.fit(epoch_num=50, learning_rate="lr_find",learning_rate_iteration=200)
alg.predict()
anoms, _ , _ = alg.getAnomalies()
print(anoms)
print(c_f1_score(anoms, np.array(alg.Y_test_df)))
- Example on how to put your local data into a DatasetSpecification (here: WADI Dataset)
from anodilib.data.DatasetSpecification import DatasetSpecification
WADI = DatasetSpecification(
dataset_name="WADI.A2_19_Nov_2019_WADI_attackdataLABLE.csv",
location=None,
delimiter=",",
label_column=130, # column containing the label
is_data_column=lambda c: c != 130 and c >= 3, # use data of columns
columns=None,
skip_header=3,
skip_footer=3,
label_realizations=[1, -1],
decimal=".",
only_first_n_entries=-1, # if -1, use all entries
predefined_dataset=None,
)
# use for algorithms ...
- for more information, have a look at the
anodilib/tests/
or on our Githlib Repository
Dev Installation
This package is built using poetry, run the following code to install an editable version of the package for development
pip install poetry
poetry install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
anodilib-0.1.5.tar.gz
(7.8 MB
view details)
Built Distribution
File details
Details for the file anodilib-0.1.5.tar.gz
.
File metadata
- Download URL: anodilib-0.1.5.tar.gz
- Upload date:
- Size: 7.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.6 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 550e2bdc61582924012b535fea3da7c52f67740f00a41da6393fb5e3f97b4b3d |
|
MD5 | 77cf29be43fe8ccde65990a20c2a8c13 |
|
BLAKE2b-256 | 0d7d4dd2c142d11e76721847efdef0785f0ec42e6860ce66fc1de3a12eb75557 |
File details
Details for the file anodilib-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: anodilib-0.1.5-py3-none-any.whl
- Upload date:
- Size: 7.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.9.6 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b94fae0058826d8e94305e3ab11a9415d297e75b485ee441591e85daaaa132b1 |
|
MD5 | 55bb234677217c1b464edb7fe9985d1a |
|
BLAKE2b-256 | 5ffd2ccef1b46b3e6302f53a28adc3f74ba85b5b9218c2109c10ae62bc8c8104 |