SigMahaKNN - Signature Mahalanobis KNN method
Anamoly detection on multivariate streams with Variance Norm and Path Signature
SigMahaKNN (signature_mahalanobis_knn) combines the variance norm (a
generalisation of the Mahalanobis distance) with path signatures for anomaly
detection for multivariate streams. The signature_mahalanobis_knn library is a
Python implementation of the SigMahaKNN method. The key contributions of this
library are:
- A simple and efficient implementation of the variance norm distance as
provided by the
signature_mahalanobis_knn.Mahalanobisclass. The class has two main methods:- The
fitmethod to fit the variance norm distance to a training datase - The
distancemethod to compute the distance between twonumpyarraysx1andx2
- The
- A simple and efficient implementation of the SigMahaKNN method as provided by
the
signature_mahalanobis_knn.SigMahaKNNclass. The class has two main methods:- The
fitmethod to fit a model to a training dataset- The
fitmethod can take in a corpus of streams as its input (where we will compute path signatures of using thesktimelibrary withesigoriisignature) or a corpus of path signatures as its input. This also opens up the possibility of using other feature represenations and applications of using the variance norm distance for anomaly detection - Currently, the library uses either
sklearn'sNearestNeighborsclass orpynndescent'sNNDescentclass to efficiently compute the nearest neighbour distances of a new data point to the corpus training data
- The
- The
conformancemethod to compute the conformance score for a set of new data points- Similarly to the
fitmethod, theconformancemethod can take in a corpus of streams as its input (where we will compute path signatures of using thesktimelibrary withesigoriisignature) or a corpus of path signatures as its input
- Similarly to the
- The
Installation
The SigMahaKNN library is available on PyPI and can be installed with pip:
pip install signature_mahalanobis_knn
Usage
As noted above, the signature_mahalanobis_knn library has two main classes:
Mahalanobis, a class for computing the variance norm distance, and
SigMahaKNN, a class for computing the conformance score for a set of new data
points.
Computing the variance norm distance
Using the SigMahaKNN method for anomaly detection
Repo structure
The core implementation of the SigMahaKNN method is in the
src/signature_mahalanobis_knn folder:
mahal_distance.pycontains the implementation of theMahalanobisclass to compute the variance norm distancesig_maha_knn.pycontains the implementation of theSigMahaKNNclass to compute the conformance scores for a set of new data points against a corpus of training datautils.pycontains some utility functions that are useful for the librarybaselines/is a folder containing some of the baseline methods we look at in the paper - see paper-examples/README.md for more details
Examples
There are various examples in the examples and paper-examples folder:
examplescontains small examples using randomly generated data for illustration purposespaper-examplescontains the examples used in the paper (link available soon!) where we compare the SigMahaKNN method to other baseline approaches (e.g. Isolation Forest and Local Outlier Factor) on real-world datasets- There are notebooks for downloading and preprocessing the datasets for the examples - see paper-examples/README.md for more details
Contributing
To take advantage of pre-commit, which will automatically format your code and
run some basic checks before you commit:
pip install pre-commit # or brew install pre-commit on macOS
pre-commit install # will install a pre-commit hook into the git repo
After doing this, each time you commit, some linters will be applied to format
the codebase. You can also/alternatively run pre-commit run --all-files to run
the checks.
See CONTRIBUTING.md for more information on running the test
suite using nox.
Metadata
Release files for signature-mahalanobis-knn 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| signature_mahalanobis_knn-0.1.0.tar.gz | 5.8 MB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| signature_mahalanobis_knn-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.8 MB
Release files / signature_mahalanobis_knn-0.1.0.tar.gz
| Download URL | signature_mahalanobis_knn-0.1.0.tar.gz |
|---|---|
| Size | 5.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
77269ee87648f4501e1fda3bb624d48ae137f707ad78df939a8709502dfa78f8
|
|
BLAKE2b-256 checksum How to use checksums |
44093cfe7f41d1380d7666b81ad039fd343304866fddc0fa9928fbeace061b66
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / signature_mahalanobis_knn-0.1.0-py3-none-any.whl
| Download URL | signature_mahalanobis_knn-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9ac3436cf6529f61f6acf70acd6324d109e85ea39a59bcfe4593a14036a1315
|
|
BLAKE2b-256 checksum How to use checksums |
59c34634a0686f1cddadf010a60ba5ea5cbf98e347849dc60b412f499a3973a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for signature-mahalanobis-knn 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.