A Python-native property-graph and graph-ML toolkit for fraud detection, segmentation, and recommendation use cases -- no database server required.
Project description
mlgraphs
A pip-installable, Neo4j-flavored property-graph and graph-ML toolkit for fraud detection, customer segmentation, recommendation, and general graph-derived features — no graph database server required.
mlgraphs gives you nodes, typed relationships, and properties as first-class
citizens (the same property-graph model Neo4j uses), a Cypher-like pattern
DSL, and a set of use-case packs built on top of NetworkX rather than a
custom storage engine.
Install
pip install mlgraphs
From a local checkout (with optional extras):
pip install -e ".[gnn,embeddings,dev,notebooks]"
from mlgraphs import PropertyGraph
(Extras are optional and independent: gnn pulls in PyTorch + PyTorch
Geometric, embeddings pulls in gensim for node2vec, notebooks pulls in
Jupyter/matplotlib for the example notebooks. The core install only needs
NetworkX, NumPy, pandas, and python-louvain.)
Quick example
from mlgraphs import PropertyGraph, node, rel
g = PropertyGraph()
g.add_node("Person", id="alice", name="Alice")
g.add_node("Person", id="bob", name="Bob")
g.add_relationship("alice", "FRIEND_OF", "bob")
pattern = node("Person", name="Alice").as_("a") >> rel("FRIEND_OF") >> node("Person").as_("f")
for binding in g.match(pattern):
print(binding["f"]) # "bob"
What's included
| Module | What it does |
|---|---|
mlgraphs.core |
PropertyGraph — nodes, typed relationships, properties, from_dataframes() |
mlgraphs.query |
Cypher-style pattern matching: node(...) >> rel(...) >> node(...) |
mlgraphs.algorithms |
PageRank, centrality, Louvain communities, shortest path |
mlgraphs.fraud |
Shared-attribute ring detection, fan-in/fan-out transaction features |
mlgraphs.anomaly |
Z-score outliers, fan-out/fan-in hub detection, closed transaction-loop detection |
mlgraphs.recommendation |
Co-occurrence graphs, collaborative filtering, link-prediction features |
mlgraphs.tabular |
Flatten any feature pack into a pandas DataFrame for sklearn/XGBoost/LightGBM |
mlgraphs.embeddings |
node2vec via gensim — graph embeddings, no deep learning framework needed |
mlgraphs.splits |
Component-aware and temporal train/test splitting (avoids graph leakage) |
mlgraphs.gnn |
Bridge to PyTorch Geometric for GNN-based scoring |
Examples
examples/fraud_ring_detection.py— synthetic transactions with planted fraud rings, end to end: graph construction → ring detection → GraphSAGE scoring.notebooks/01_customer_analytics_online_retail.ipynb— outlier/anomaly detection, recommendation, next best action, segmentation (graph community + ML clustering), and churn prediction on the real Online Retail II dataset (UCI Machine Learning Repository).notebooks/02_recommendation_segmentation_movielens.ipynb— recommendation and segmentation on the real MovieLensml-latest-smalldataset (GroupLens Research).
Notebook datasets aren't committed to this repo (see .gitignore); each
notebook's first cell documents where to download them from.
Testing
pytest tests/
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mlgraphs-0.2.0.tar.gz.
File metadata
- Download URL: mlgraphs-0.2.0.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1baf3292c9c78a7f7ae51769e27b4790506ff900d8248d5e362630cf91ad6de6
|
|
| MD5 |
007a93dc1fbd1b530d3e2d0c176bbad2
|
|
| BLAKE2b-256 |
6e135b02fe6c75d43cc888d4c3ed1d4d70416baa652cf30587b6cc3c064a6df1
|
File details
Details for the file mlgraphs-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mlgraphs-0.2.0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2a3946aa1064bb0da3b38ed3e78648dc0e36cdc81151e056b6df6b3fac8548d
|
|
| MD5 |
588719a477f34332fbf6b914a563185b
|
|
| BLAKE2b-256 |
e9c74cf793e61ec0ff549b3257cfcbb26c5d2c7875ec5c885458db3096bd1cc9
|