Package: signature-mahalanobis-knn
SigMahaKNN - Signature Mahalanobis KNN methodAnamoly detection on multivariate streams with Variance Norm and Path SignatureSigMahaKNN (signature_mahalanobis_knn) combines the variance norm (a
generalisation of the Mahalanobis distance) with path signatures for anomaly
detection for multivariate streams. Thesignature_mahalanobis_knnlibrary 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 thesignature_mahalanobis_knn.Mahalanobisclass. The class has
two main methods:Thefitmethod to fit the variance norm distance to a training dataseThedistancemethod to compute the distance between twonumpyarraysx1andx2A simple and efficient implementation of the SigMahaKNN method as provided by
thesignature_mahalanobis_knn.SigMahaKNNclass. The class has two main
methods:Thefitmethod to fit a model to a training datasetThefitmethod can take in a corpus of streams as its input (where we
will compute path signatures of using thesktimelibrary withesigoriisignature)ora 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 detectionCurrently, the library uses eithersklearn'sNearestNeighborsclass orpynndescent'sNNDescentclass to efficiently compute the nearest
neighbour distances of a new data point to the corpus training dataTheconformancemethod to compute the conformance score for a set of new
data pointsSimilarly to thefitmethod, theconformancemethod can take in a
corpus of streams as its input (where we will compute path signatures of
using thesktimelibrary withesigoriisignature)ora corpus of
path signatures as its inputInstallationThe SigMahaKNN library is available on PyPI and can be installed withpip:pipinstallsignature_mahalanobis_knnUsageAs noted above, thesignature_mahalanobis_knnlibrary has two main classes:Mahalanobis, a class for computing the variance norm distance, andSigMahaKNN, a class for computing the conformance score for a set of new data
points.Computing the variance norm distanceUsing the SigMahaKNN method for anomaly detectionRepo structureThe core implementation of the SigMahaKNN method is in thesrc/signature_mahalanobis_knnfolder: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 - seepaper-examples/README.mdfor more
detailsExamplesThere are various examples in theexamplesandpaper-examplesfolder: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 datasetsThere are notebooks for downloading and preprocessing the datasets for the
examples - seepaper-examples/README.mdfor more
detailsContributingTo take advantage ofpre-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 repoAfter doing this, each time you commit, some linters will be applied to format
the codebase. You can also/alternatively runpre-commit run --all-filesto run
the checks.SeeCONTRIBUTING.mdfor more information on running the test
suite usingnox.