Skip to main content

Graph Neural Network-Based Anomaly Detection (GNNAD)

gnnad is a package for anomaly detection on multivariate time series data.

This model builds on the recently-proposed Graph Deviation Network (GDN)1, a graph neural network model that uses embeddings to capture inter-sensor relationships as a learned graph, and employs graph attention-based forecasting to predict future sensor behaviour. Anomalies are flagged when the error scores are above a calculated threshold value. By learning the interdependencies among variables and predicting based on the typical patterns of the system, this approach is able to detect deviations when the expected spatial dependencies are disrupted. As such, GDN offers the ability to detect even the small-deviation anomalies generally overlooked by other distance based and density based anomaly detection methods for time series.

This package accompanies work that further develops this model2, and introduces an alternate anomaly threshold criteria based on the learned graph, with the improved ability to detect anomalies in multivariate timeseries data.

Quick start

As an example we'll explore data collected within river network system. In particular data collected on the Herbert river network, at these sensor locations:

Herbert river sensor locations

The sensors measure water level, from within the river. Assuming we have pre-processed the data, we instantiate and fit the model:

from gnnad.graphanomaly import GNNAD

# run model
model = GNNAD(threshold_type="max_validation", topk=6, slide_win=200)
fitted_model = model.fit(X_train, X_test, y_test)

# the predicted values can be accessed here
test_predict = fitted_model.test_result[0, :, i]

We can visualise the predicted values vs. actual values, with helper functions in the plot module.

Herbert river sensor locations

Note that some locations closer to the outlet are influenced by tidal patterns. The error scores that are obtained from this forecasting model are then transformed and, if they exceed the calculated threshold, flagged as an anomaly. The bottom indicates if any sensor flagged an anomaly, and compares this to the ground truth labels, for the test data.

The performance of the anomaly detection classification model can be analysed by:

fitted_model.print_eval_metrics()
>>> recall: 30.4
>>> precision: 59.3
>>> accuracy: 49.7
>>> specificity: 73.9
>>> f1: 40.2

Check out full details in the example notebook

Installation

gnnad is compatible with python versions 3.8, 3.9, 3.10 and 3.11. You can install the latest release with pip:

pip install gnnad

If you would like the latest development version you can install directly from github:

pip install https://github.com/KatieBuc/gnnad.git

Developer installation

You'll need poetry. Once you have it installed and cloned the repo you can install with (from the repo directory):

poetry install

Citation

MLA:

Buchhorn, Katie, et al. "Graph Neural Network-Based Anomaly Detection for River Network Systems"
arXiv preprint arXiv:2304.09367 (2023).

BibTeX:

@article{buchhorn2023graph,
  title={Graph Neural Network-Based Anomaly Detection for River Network Systems},
  author={Buchhorn, Katie and Mengersen, Kerrie and Santos-Fernandez, Edgar and Salomone, Robert},
  journal={arXiv preprint arXiv:2304.09367},
  year={2023}
}
  1. Deng, Ailin, and Bryan Hooi. "Graph neural network-based anomaly detection in multivariate time series." Proceedings of the AAAI conference on artificial intelligence. Vol. 35. No. 5. 2021.

  2. Buchhorn, Katie, et al. "Graph Neural Network-Based Anomaly Detection for River Network Systems" Under review.

Release files for gnnad 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gnnad 0.1.1
File Size Uploaded
gnnad-0.1.1.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gnnad 0.1.1
File Interpreter ABI Platform
gnnad-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 35.0 kB

Release files / gnnad-0.1.1.tar.gz

Download URL gnnad-0.1.1.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f3c50822072870f82b6f2ada5c124ed55b290646c73f570688e9a73bf4eb4050
BLAKE2b-256 checksum
How to use checksums
49138c28d72cb2511ee4a843aade0f03f64311ac35a4cf38ad7d0989dae0a9df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / gnnad-0.1.1-py3-none-any.whl

Download URL gnnad-0.1.1-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04599ae98de516bcbec5453bd4606e0bea4900e322d7ec260bffd68cd1c5ee03
BLAKE2b-256 checksum
How to use checksums
59fb19f108fafa3cf699c09d51f3aaa89ee0223404b36a304ed07b851204aa9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page