Skip to main content

Graph Neural Network-Based Anomaly Detection (GNNAD)

Project description

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) [2], 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 model [1], and introduces an alternate anomaly threshold criteria based on the learned graph, with the improved ability to detect anomalies in multivariate timeseries data. The example we explore is of data collected within river network systems.

Quick start

Consider 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:

# 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

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

Once the project is release on PyPI it should be as simple as:

pip install gnnad

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

References

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

[2] 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.

Citation

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gnnad-0.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

gnnad-0.1.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file gnnad-0.1.0.tar.gz.

File metadata

  • Download URL: gnnad-0.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for gnnad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fff616db35c0098c76e78eebff589f5ac249423117c1e87e489b98b666240770
MD5 c07a0a7be92f20df93f6a3bc77e856e3
BLAKE2b-256 1992612bd884eadb274c435f54bddf1a89e5a02904bda2f8a4471623140e904d

See more details on using hashes here.

File details

Details for the file gnnad-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gnnad-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for gnnad-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94b50d84de96ba47848491432c3bce9e10c70e7f4f1b908a965a71ce715640e5
MD5 b32a1228e23cbe1494a1ce9800787695
BLAKE2b-256 a8d4e4f4e6253367ee2eb0b4f247ddc44f5cbeb9db5e086c9ed1f7fc276acda2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page