Skip to main content

Density-Ratio Adaptive Spectral Clustering: a scikit-learn-compatible clustering estimator.

Project description

DRASC — Density-Ratio Adaptive Spectral Clustering

A small, dependency-light, scikit-learn-compatible clustering estimator.

DRASC builds a sparse k-nearest-neighbour graph with a self-tuning (per-point adaptive) bandwidth, down-weights edges that bridge regions of very different density via a density-ratio term raised to the power gamma, and then runs normalized spectral clustering on the resulting graph.

Installation

pip install drasc

Or from a local checkout:

pip install .

Requires Python ≥ 3.9 and numpy, scipy, scikit-learn (installed automatically).

Quick start

from sklearn.datasets import load_wine
from sklearn.preprocessing import StandardScaler
from drasc import DRASC

X = StandardScaler().fit_transform(load_wine().data)

model = DRASC(n_clusters=3)
labels = model.fit_predict(X)

Because it follows the scikit-learn estimator API, it works with Pipeline, GridSearchCV, and the sklearn.metrics clustering scores:

from sklearn.pipeline import make_pipeline
from sklearn.metrics import adjusted_rand_score

pipe = make_pipeline(StandardScaler(), DRASC(n_clusters=3))
labels = pipe.fit_predict(X)

Parameters

Parameter Default Description
n_clusters Number of clusters to form (required, ≥ 2).
n_neighbors None Graph neighbours; Nonemax(10, ceil(2·log2 n)).
gamma 2.0 Density-ratio exponent. 0 disables reweighting.
random_state 0 Seed for the final k-means step.
n_init 30 k-means initializations on the embedding.
n_jobs -1 Parallel jobs for the neighbour search.

Fitted attributes

  • labels_ — cluster label per sample.
  • embedding_ — row-normalized spectral embedding (n_samples, n_clusters).
  • eigengap_ — relative eigengap at the n_clusters boundary, useful for selecting n_clusters / gamma / n_neighbors.

Tips

  • Standardize your features first (e.g. StandardScaler). DRASC uses Euclidean distances, so feature scales matter.
  • For high-dimensional data, reduce with PCA before clustering.
  • Sweep eigengap_ over candidate settings to pick hyperparameters without labels.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drasc-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drasc-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file drasc-0.1.0.tar.gz.

File metadata

  • Download URL: drasc-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for drasc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 060c9e03db9c7c7e7402e23bf0a134ed0e0b161c388c52d5e3fe3da3fe38f8f4
MD5 7b381ddf6f2912adf89265775e7a0ab7
BLAKE2b-256 8de58e21d27b1085d1bd8a8952247b39d9fee91289adffa76e07ce03196d3364

See more details on using hashes here.

File details

Details for the file drasc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: drasc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for drasc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 722fa67fee836ca4419b1a588a7ab35b79591ddd00dd7e3bd4c14929bceaf70c
MD5 1d71ac27ca0e7c0f0a6988f22020d64a
BLAKE2b-256 be263e544b0c9da45288abceac203c052ca4f019a3b8e7003c0d15cc58ea95a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page