Graph-Based Clustering
Graph-Based Clustering using connected components and minimum spanning trees.
Both clustering methods, supported by this library, are transductive - meaning they are not designed to be applied to new, unseen data.
Installation
To install graph-based-clustering run:
pip install graph-based-clustering
Usage
The library has sklearn-like fit/fit_predict interface.
ConnectedComponentsClustering
This method computes pairwise distances matrix on the input data, and using threshold (parameter provided by the user) to binarize pairwise distances matrix makes an undirected graph in order to find connected components to perform the clustering.
Required arguments:
- threshold - paremeter to binarize pairwise distances matrix and make undirected graph
Optional arguments:
- metric - sklearn.metrics.pairwise_distances parameter (default: "euclidean")
- n_jobs - sklearn.metrics.pairwise_distances parameter (default: None)
Example:
import numpy as np
from graph_based_clustering import ConnectedComponentsClustering
X = np.array([[0, 1], [1, 0], [1, 1]])
clustering = ConnectedComponentsClustering(
threshold=0.275,
metric="euclidean",
n_jobs=-1,
)
clustering.fit(X)
labels_pred = clustering.labels_
# alternative
labels_pred = clustering.fit_predict(X)
SpanTreeConnectedComponentsClustering
This method computes pairwise distances matrix on the input data, builds a graph on the obtained matrix, finds minimum spanning tree, and finaly, performs the clustering through dividing the graph into n_clusters (parameter given by the user) by removing n-1 edges with the highest weights.
Required arguments:
- n_clusters - the number of clusters to find
Optional arguments:
- metric - sklearn.metrics.pairwise_distances parameter (default: "euclidean")
- n_jobs - sklearn.metrics.pairwise_distances parameter (default: None)
Example:
import numpy as np
from graph_based_clustering import SpanTreeConnectedComponentsClustering
X = np.array([[0, 1], [1, 0], [1, 1]])
clustering = SpanTreeConnectedComponentsClustering(
n_clusters=3,
metric="euclidean",
n_jobs=-1,
)
clustering.fit(X)
labels_pred = clustering.labels_
# alternative
labels_pred = clustering.fit_predict(X)
Comparing on sklearn toy datasets
ConnectedComponentsClustering
SpanTreeConnectedComponentsClustering
Requirements
Python >= 3.7
Citation
If you use graph-based-clustering in a scientific publication, we would appreciate references to the following BibTex entry:
@misc{dayyass2021graphbasedclustering,
author = {El-Ayyass, Dani},
title = {Graph-Based Clustering using connected components and spanning trees},
howpublished = {\url{https://github.com/dayyass/graph-based-clustering}},
year = {2021}
}
Metadata
Release files for graph-based-clustering 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 | Actions |
|---|---|---|---|---|
| graph-based-clustering-0.1.0.tar.gz | 7.4 kB | Without provenance | Details for graph-based-clustering-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| graph_based_clustering-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for graph_based_clustering-0.1.0-py3-none-any.whl |
Total release size: 16.5 kB
Release files / graph-based-clustering-0.1.0.tar.gz
| Download URL | graph-based-clustering-0.1.0.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a87b9a865249e3bbda8c7894852f0cf31647162e0e85a04a4bf0a3dba6f455c
|
|
BLAKE2b-256 checksum How to use checksums |
2c0f3626835f503a3d0f4f9d5bb668761230f81060be03c2e62d9cbf74b4adef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
|
Release files / graph_based_clustering-0.1.0-py3-none-any.whl
| Download URL | graph_based_clustering-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb1ba7c278d5b51351d3a8491dda2b6b6dda2bc2dd6ef9be4a2545154c7f710b
|
|
BLAKE2b-256 checksum How to use checksums |
d3705483b7e506396ae04c837dfaea799ebcea31aeda2df54284f59f5c0bf7ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.5
|
Security for graph-based-clustering 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.