Skip to main content

ClusTrust

A desktop tool and Python library that answers two questions about clustering: how many clusters are in my data, and can I trust them?

Validity indices such as the silhouette always return a best number of clusters of two or more, even for data with no groups. ClusTrust runs several algorithms over a range of k, scores them with validity indices, tests stability by resampling, builds a consensus clustering, and compares every score with structureless reference data. The honest answer can therefore be "no evidence of clusters".

No clusters found Ambiguous structure

Features

  • Null-calibrated scores: silhouette, Calinski-Harabasz and Davies-Bouldin are turned into z-scores against structureless data (Gaussian null, uniform-over-principal-components null, or both; the default requires beating both).
  • One evidence profile per k: calibrated indices, resampling stability, PAC and agreement between algorithms, with a verdict: Clear structure, Weak or ambiguous structure or No evidence of clusters.
  • Trust at three levels: for the whole solution, for each cluster (Jaccard stability) and for each point (consensus confidence).
  • No programming needed: an offline Tkinter interface; your data stays on your computer.
  • Reproducible: one global seed, and every session can be exported as session.json plus a replay.py script that repeats the analysis.

Algorithms: k-means, agglomerative clustering, Gaussian mixture. Input: CSV files (numeric columns are used).

Install

Requires Python 3.10 or later, with Tkinter available in your Python installation.

pip install "clustrust[full]"

Or from source:

git clone https://github.com/elenamehana/clustrust.git
cd clustrust
pip install -e ".[full]"

The full extra installs diptest, which enables the dip test in the tendency check. Without it everything else still works.

Start the graphical interface

python -m clustrust
  1. Click Load CSV. Set scaling, missing-value handling, optional log(1 + x) and optional PCA, then click Apply to data.
  2. Choose the algorithms, the range of k, the seed and the Run size:
    • quick: 20 resamples, 20 null sets, Gaussian null. For exploring.
    • literature: 100 resamples, 100 null sets, both nulls. Much slower (roughly an hour on a 2-core laptop for a few hundred rows).
  3. Optional first step: Check tendency (Hopkins statistic and dip test).
  4. Run evidence analysis gives the verdict, the best-supported k and the table of criteria for every k. Thresholds can be changed and the verdict refreshed with Update verdict; Literature defaults restores the published values.
  5. Run consensus builds the final grouping with confidence per point, trust per cluster and a profile of what each cluster looks like.
  6. Export session saves the settings, parameter sources, package versions, results and a replay script.

Hover over any control for a plain-language explanation and the default with its source.

Quick start from Python

from clustrust.io.loaders import load_csv, prepare
from clustrust.core.evidence import evidence_profile, summarize

df = load_csv("examples/overlap_blobs/overlap_blobs.csv")
X, columns = prepare(df, scale="standard")
prof, cal = evidence_profile(X, k_range=range(2, 7), n_null=20, n_rounds=20)
print(prof.round(3))
print(summarize(prof))   # verdict, reason, best_k, passing k

evidence_profile with no arguments uses the literature defaults (100 null sets, 100 resamples, both nulls).

How the verdict works

For each k, ClusTrust checks that at least 2 of the 3 indices beat the null (z above 2), that stability is at least 0.80 and that agreement between algorithms is at least 0.80.

  • No index beats the null at any k: No evidence of clusters.
  • Exactly one k passes, or the lowest-PAC k among the passing k is also favoured by most indices: Clear structure.
  • Otherwise: Weak or ambiguous structure, with the passing k and the index favourites listed.

Every threshold is an adjustable default, not a validated constant. Their sources are listed in src/clustrust/core/defaults.py and recorded in every session.json.

Worked examples

The examples/ folder holds the data, the exported session and the results for each case study. All use the literature preset (seed 42, k = 2 to 8, three algorithms).

Example Data Verdict
wine 178 wines, 13 chemical measurements Clear structure, k = 3
wholesale 440 customers, 6 spending variables (log-transformed) Weak or ambiguous structure
gene_expression 801 tumours, 500 genes, PCA to 20 components Weak or ambiguous (k = 3 to 8 all pass)
wine_shuffled Wine with every column permuted: structureless control No evidence of clusters
noise 500 points, 2 Gaussian variables, no groups No evidence of clusters
noise_uniform 500 points, 3 uniform variables, no groups No evidence of clusters
overlap_blobs 500 points, 4 overlapping true groups Weak or ambiguous (k = 3, 4, 5 pass; best k = 4)

Each folder has a replay.py (run it inside the folder to reproduce the analysis), a NOTES.md where available, and a DATA_LICENSE.md with the source and licence. Reference labels are used only after the analysis, to check the results (benchmarks/check_labels.py).

The real datasets come from the UCI Machine Learning Repository under CC BY 4.0. Re-create them with python examples/make_examples.py (needs pip install ucimlrepo) python examples/make_gene_expression.py (needs the manually downloaded TCGA archive) and python examples/make_synthetic.py (generates the three synthetic examples).

Benchmarks

benchmarks/run_benchmark.py runs a sanity check on generated data: noise, blobs and two moons. benchmarks/sensitivity.py shows how the verdict changes when the thresholds change. These are sanity checks with small samples, not validated error rates.

Limitations

  • Three algorithms only; non-convex shapes (for example two moons) are not recovered.
  • Numeric data only; the interface limits consensus to 2000 rows.
  • The verdict depends on adjustable thresholds, some of which are literature values applied by analogy.
  • The evidence profile is best read as a set of plausible k with reasons, not as a point estimate of k. When several k pass, the best-supported k is the coarsest by PAC tie-break.
  • Stability and consensus can look convincing on structureless data; only the null calibration exposes this.

Tests

pip install -e ".[full,dev]"
pytest

Continuous integration runs the tests on Windows and Linux with Python 3.10 and 3.12.

License and citation

MIT License (see LICENSE). If you use this software, please cite it (see CITATION.cff).

Metadata

Release files for clustrust 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 clustrust 0.1.0
File Size Uploaded Provenance Actions
clustrust-0.1.0.tar.gz 35.6 kB Without provenance Details for clustrust-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 70.3 kB

Release files / clustrust-0.1.0.tar.gz

Download URL clustrust-0.1.0.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dffd79923b94163b66bcafa20e275029dcd68dc05967a7c460a7f3026aedbcc3
BLAKE2b-256 checksum
How to use checksums
8f46ee268dac0c5503b82fd20f8a135cc63cfb3a70aa3b0c3deb6fdc3bd689bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

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

Download URL clustrust-0.1.0-py3-none-any.whl
Size 34.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b728bbf3767e82717c00e5e0bbd1d6d7ea334f1311b6cb86c0ea2206fe637152
BLAKE2b-256 checksum
How to use checksums
2a241f4ebf31082da5d7c131a8b4295de7370d97ddea32c5fbf3f6d4ff3235fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Security for clustrust 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