Skip to main content

IncrementalDBSCAN

incdbscan is an implementation of IncrementalDBSCAN, the incremental version of the DBSCAN clustering algorithm.

IncrementalDBSCAN lets the user update the clustering by inserting or deleting data points. The algorithm yields the same result as DBSCAN but without reapplying DBSCAN to the modified data set.

Thus, IncrementalDBSCAN is ideal to use when the size of the data set to cluster is so large that applying DBSCAN to the whole data set would be costly but for the purpose of the application it is enough to update an already existing clustering by inserting or deleting some data points.

The implementation is based on the following paper. To see what's new compared to the paper, jump to Notes on the IncrementalDBSCAN paper.

Ester, Martin; Kriegel, Hans-Peter; Sander, Jörg; Wimmer, Michael; Xu, Xiaowei (1998). Incremental Clustering for Mining in a Data Warehousing Environment. In: Proceedings of the 24rd International Conference on Very Large Data Bases (VLDB 1998).

indbscan illustration

Table of Contents

Highlights

The incdbscan package is an implementation of the IncrementalDBSCAN algorithm by Ester et al., with about 40 unit tests covering diverse cases, and with additional corrections to the original paper.

Installation

incdbscan is on PyPI, and can be installed with pip:

pip install incdbscan

The latest version of the package requires at least Python 3.11.

Usage

The algorithm is implemented in the IncrementalDBSCAN class.

There are 3 methods to use:

  • insert for inserting data points into the clustering
  • delete for deleting data points from the clustering
  • get_cluster_labels for obtaining cluster labels

All methods take a batch of data points in the form of an array of shape (n_samples, n_features) (similar to the scikit-learn API).

from sklearn.datasets import load_iris
X = load_iris()['data']
X_1, X_2 = X[:100], X[100:]

from incdbscan import IncrementalDBSCAN
clusterer = IncrementalDBSCAN(eps=0.5, min_pts=5)

# Insert 1st batch of data points and get their labels
clusterer.insert(X_1)
labels_part1 = clusterer.get_cluster_labels(X_1)

# Insert 2nd batch and get labels of all points in a one-liner
labels_all = clusterer.insert(X_2).get_cluster_labels(X)

# Delete 1st batch and get labels for 2nd batch
clusterer.delete(X_1)
labels_part2 = clusterer.get_cluster_labels(X_2)

For a longer description of usage check out the notebook developed just for that!

Performance

Performance has two components: insertion and deletion cost. The results below are based on measurements using data sets in the 1K-10K size range.

indbscan performance

The cost of inserting a new data point with IncrementalDBSCAN is quite small and grows slower than the cost of applying (scikit-learns's) DBSCAN to a whole data set. In other words, given that we have a data set D clustered with IncrementalDBSCAN, and we want to see which cluster would a new object P belong to, it is faster to insert P into the current IncrementalDBSCAN clustering than to apply DBSCAN to the union of D and {P}.

The cost of deleting a data point with IncrementalDBSCAN is quite small and grows slower than the cost of applying DBSCAN to the data set minus that data point. In other words, given that we have a data set D clustered with IncrementalDBSCAN, and we want to see what happens to the clustering after removing an object P from the data set, it is faster to delete P from the existing IncrementalDBSCAN clustering than to apply DBSCAN to the difference of D and {P}.

These results do not imply that it is efficient to cluster a whole data set with IncrementalDBSCAN insertions. If we measure the time to cluster a data set of a given size with DBSCAN versus IncrementalDBSCAN, IncrementalDBSCAN will be slower compared to DBSCAN. The advantage of IncrementalDBSCAN is the efficiency of making additional changes (insertions, deletions) to an already clustered data set, not clustering from scratch.

A typical performance number is that clustering 8,000 data points takes about 600-700 ms with this implementation.

See this notebook about performance for more details.

Metadata

Release files for incdbscan 0.6.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 incdbscan 0.6.0
File Size Uploaded Provenance
incdbscan-0.6.0.tar.gz 19.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for incdbscan 0.6.0
File Interpreter ABI Platform
incdbscan-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 43.1 kB

Release files / incdbscan-0.6.0.tar.gz

Download URL incdbscan-0.6.0.tar.gz
Size 19.5 kB
Tags Source
SHA-256 checksum
How to use checksums
02a65b8760e81edd23098324f89b641d64c18057d287777c391d48c07eba99dd
BLAKE2b-256 checksum
How to use checksums
d2319555135b1c8d460be33accccb787b4a182ab1961c5922086feb696e7a9bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.11.14 Darwin/23.6.0

Release files / incdbscan-0.6.0-py3-none-any.whl

Download URL incdbscan-0.6.0-py3-none-any.whl
Size 23.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
67aae4af7dbf876ac7f51627c8611957a80e7d9356279b73ee5ac06a263bdd46
BLAKE2b-256 checksum
How to use checksums
7153ebb2cc81b84800f2b83ee4f3671ede212bd5f8f7a7cb0e931c60e2b4dcaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.11.14 Darwin/23.6.0

Security for incdbscan 0.6.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.

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