outgraph
outgraph is a simple outlier detection algorithm for graph datasets. Given a list of graphs, it uses Mahalanobis distance detect which graphs are outliers based on either their topology or node attributes.
Note:
outgraphonly works for datasets where each graph has an equal number of nodes.
Installation
You can install outgraph with pip:
$ pip install outgraph
How it Works
Unlike most approaches to graph outlier detection, outgraph does not use machine learning. Instead, each graph is converted into a vector representation using one of three available methods:
- Averaging the node feature/attribute vectors
- Flattening the adjacency matrix
- A concatenation of 1 and 2
Then, the Mahalanobis distance between each vector and the distribution of vectors is calculated. Lastly, a Chi-Squared distribution is used to model the distribution of distances and identify the distances outside a cutoff threshold (e.g. p < 0.05).
This approach is based off this article.
Usage
Each graph in your dataset needs to be an instance of outgraph.Graph. This object has two parameters, node_attrs and adjacency_matrix –– both numpy arrays where the indices correspond to nodes. Example:
import numpy as np
from outgraph import Graph
node_attrs = np.array([[-1], [0], [1]])
adj_matrix = np.array([[1, 1, 0],
[1, 1, 1],
[0, 1, 1]])
graph = Graph(node_attrs, adj_matrix)
Once you have a list of Graph objects, simply submit them into outgraph.detect_outliers:
from outgraph import Graph, detect_outliers
graphs = [Graph(), ...]
outliers, indices = detect_outliers(graphs, method=1, p_value=0.05)
Notice the method and p_value parameters. The method parameter is an integer between 1 and 3 that corresponds to one of the three graph vectorization methods described in the  section. p_value is the outlier cutoff threshold.
Metadata
Release files for outgraph 1.0.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 | Actions |
|---|---|---|---|---|
| outgraph-1.0.0.tar.gz | 3.7 kB | Without provenance | Details for outgraph-1.0.0.tar.gz |
Release files / outgraph-1.0.0.tar.gz
| Download URL | outgraph-1.0.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fef669301782d7d4faff566f65d745113c3bfdbb69571cf8e6158f18b51c7a95
|
|
BLAKE2b-256 checksum How to use checksums |
a70613c3c47e446b31a682e7d5b44f4af3f5bcc7c3953229fcb6e2835072212d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for outgraph 1.0.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.