Skip to main content

iterative-dbscan

Silhouette-guided recursive refinement of DBSCAN. A modern, pip-installable implementation of the LENTA algorithm from:

Morichetta & Mellia, LENTA: Longitudinal Exploration for Network Traffic Analysis from Passive Data, IEEE Transactions on Network and Service Management, 2019. DOI

What problem does it solve?

Standard DBSCAN with a single eps finds a partition that is appropriate at that one density scale. When the data has clusters at multiple density scales, or when one cluster is internally heterogeneous, you get either:

  • one giant blob that should be several clusters, or
  • everything fragmented into noise.

IterativeDBSCAN runs DBSCAN, then for any cluster whose mean silhouette falls below smin it extracts that cluster's local distance matrix, picks a new eps from its own k-distance graph, and re-clusters within. Repeat until every cluster is tight enough, or max_depth is reached.

Install

pip install iterative-dbscan

For development:

git clone https://github.com/AndreaMorichetta/iterative-dbscan
cd iterative-dbscan
pip install -e ".[dev]"
pytest

Quick start

From feature vectors

import numpy as np
from iterative_dbscan import IterativeDBSCAN

X = np.random.RandomState(0).randn(200, 10)

idb = IterativeDBSCAN(
    metric="euclidean",
    min_samples=5,
    smin=0.1,                  # split clusters whose silhouette < 0.1
    percentile_to_cluster=65,  # auto-eps percentile (LENTA default)
    max_depth=10,
)
labels = idb.fit_predict(X)
print(idb.cluster_tree_)        # readable hierarchy of splits
print(idb.silhouette_per_cluster_)

From a precomputed distance matrix

from sklearn.metrics import pairwise_distances
D = pairwise_distances(X, metric="cosine")
idb = IterativeDBSCAN(metric="precomputed", min_samples=5, smin=0.1)
labels = idb.fit_predict(D)

Parameters

The parameters follow the ones used in classic DBSCAN. The main differences are:

  • smin: by changing this parameter you decide which threshold of silhouette score would trigger a split.
  • percentile_to_cluster: important to extract the epsilon value from the k-distance graph.
  • max_depth: the maximun number of interactions
  • noisify_unsplittable: it is a boolean that let you decide to directly put low-silhouette clusters in noise.
Parameter Default Description
metric "euclidean" Distance metric, or "precomputed" to pass a distance matrix.
min_samples 5 DBSCAN min_samples (also k for the auto-eps k-distance graph).
smin 0.0 Silhouette threshold. Clusters below this get split further.
percentile_to_cluster 65.0 Auto-eps percentile (0-100, exclusive).
max_depth 10 Maximum recursion depth per cluster lineage.
eps None Override the top-level auto-eps if set.
noisify_unsplittable False If True, low-silhouette clusters that can't be split become noise.

Output attributes (after fit)

  • labels_: final cluster labels, -1 for noise
  • cluster_tree_: ClusterTree with parent-child relationships and per-node silhouette/size/depth
  • silhouette_per_cluster_: dict mapping each final label to its mean silhouette
  • n_iterations_: total number of successful splits
  • eps_initial_: the eps used at the top level

Notes

This package is a refactor of AndreaMorichetta/compute_clustering that fixes import-time issues with modern scikit-learn and numpy, and makes the algorithm safe to use as a library. It started from my need to reuse I-DBSCAN for future projects. The main differences are:

  • I dropped pyclustering (abandoned) and external hdbscan/OPTICS dependencies.
    • You can use sklearn's HDBSCAN directly if you want it.
  • Supports raw feature vectors directly, not only precomputed distance matrices.
  • Returns a ClusterTree that records the cluster-parents branch.
  • Made it more robust adding tests, and a better packaging (pyproject.toml, src/ layout).

License

MIT.

Metadata

Release files for iterative-dbscan 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iterative-dbscan 0.1.0
File Size Uploaded Provenance Actions
iterative_dbscan-0.1.0.tar.gz 14.2 kB Without provenance Details for iterative_dbscan-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iterative-dbscan 0.1.0
File Interpreter ABI Platform Actions
iterative_dbscan-0.1.0-py3-none-any.whl Python 3 none any Details for iterative_dbscan-0.1.0-py3-none-any.whl

Total release size: 26.8 kB

Release files / iterative_dbscan-0.1.0.tar.gz

Download URL iterative_dbscan-0.1.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d5ee52fb7ce534e8a4c67db3aef0e5c25ab3ab9b9fbb78c88dca41d2e6a69f07
BLAKE2b-256 checksum
How to use checksums
a71f89aa89c1240490c3b5ec2ff0f6b858db06aba1f92cabd8e751a0fce61f62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / iterative_dbscan-0.1.0-py3-none-any.whl

Download URL iterative_dbscan-0.1.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34d328708207be77b722e4b79b84de436f0924df996ed09efbffdc25f03205d9
BLAKE2b-256 checksum
How to use checksums
afe14521f4b1edc86adbba6ee4d544e1a06177bfa6e441d589f15d7f15b7eb52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for iterative-dbscan 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page