Skip to main content

silhouette-scalable

Scalable approximate silhouette scoring for k-clusterings under arbitrary metric distances.

I. Sarpe, F. Altieri, A. Pietracaprina, G. Pucci, F. Vandin. Scalable and Distributed Silhouette Approximation, arXiv, 2026. Read the paper


Install

pip install silhouette-scalable

Requires Python ≥ 3.9 and NumPy. Pre-compiled wheels are available for Linux x86_64 and macOS arm64/x86_64. No C++ compiler needed.


Quickstart

No data download required. The example runs on a synthetic dataset generated on the fly.

pip install silhouette-scalable matplotlib seaborn scikit-learn
python examples/quickstart.py  # after cloning the repo

This will:

  1. Generate 2 000 points in 8 dimensions with 5 true clusters (make_blobs)
  2. Run k-means and estimate the silhouette for k = 2,...,8
  3. Save two plots to examples/out/:
    • silhouette_distribution.png — per-cluster silhouette distributions for each k
    • silhouette_avg_vs_k.png — average silhouette vs k (the peak identifies k = 5)

Optional arguments:

python examples/quickstart.py  # after cloning the repo --k-values 2 4 6 8 10   # custom k range
python examples/quickstart.py  # after cloning the repo --t 128                 # larger sample → more accurate estimates
python examples/quickstart.py  # after cloning the repo --plots-dir ./plots     # custom output directory

Usage

import numpy as np
from sklearn.datasets import make_blobs
from sklearn.cluster import KMeans
import silhouette_scalable as ss

# Create a dataset with real cluster structure and cluster it
n_points = 50000
X, _ = make_blobs(n_samples=n_points, n_features=16, centers=8, random_state=0)
labels = KMeans(n_clusters=8, n_init=5, random_state=0).fit_predict(X)

# Per-point silhouette estimates — O(n) in the estimation step
result = ss.compute_local(X, labels, t=64, seed=0)
print(f"Global silhouette: {result['global_silhouette']:.4f}  ({result['runtime_seconds']:.2f}s)")
print(f"First 10 local estimates: {[round(v, 3) for v in result['local_silhouette'][:10]]}")

# Fast global estimate — evaluate only m << n points, much faster when n is extremely large
result = ss.compute_global(X, labels, m=500, t=64, seed=0)
print(f"Global (fast path, m=500): {result['global_silhouette']:.4f}  ({result['runtime_seconds']:.2f}s)")

# Exact silhouette — O(n^2), reduce n_points if this is too slow on your machine
result = ss.compute_exact(X, labels)
print(f"Exact global silhouette:   {result['global_silhouette']:.4f}  ({result['runtime_seconds']:.2f}s)")

Return value

All functions return a dict. The keys present depend on the function:

Key Type Present in
global_silhouette float — average silhouette score in [-1, 1] all functions
local_silhouette list[float] of length n — per-point scores compute_local, compute_uniform, compute_exact
runtime_seconds float — wall-clock time of the C++ call all functions

When to use which function

Function Cost Returns Use when
compute_local $O(nkt)$ global + per-point you need per-point values
compute_global(m=m) $O(mkt)$ global only you only need the scalar, n is large
compute_global() $O(nkt)$ global only global only, same accuracy as local
compute_uniform $O(nkt)$ global + per-point uniform-sampling baseline
compute_exact $O(n^2)$ global + per-point ground truth on small datasets

We hide $log(nk/\delta)$ factor for simplicity, check the paper for the exact complexities.

For per-point silhouette distributions and best-k selection plots, see examples/quickstart.py. compute_global scales to datasets with tens of millions of points on commodity hardware.

Distances

All functions accept a distance keyword:

ss.compute_local(X, labels, distance="manhattan")

Supported: "euclidean" (default), "sqeuclidean", "manhattan", "cosine", "canberra".

Key parameters

Parameter Default Description
t 64 PPS sample size per cluster — larger gives tighter estimates
delta 0.01 Failure probability for the approximation guarantee
m n (compute_global only) number of points to evaluate
threads 1 OpenMP thread count (Linux wheels only)
seed 100 RNG seed for reproducibility
k auto Number of clusters — inferred as max(labels)+1 if not set

Best-k selection example

import silhouette_scalable as ss
from sklearn.datasets import make_blobs

X, _ = make_blobs(n_samples=5_000, centers=5, n_features=8, random_state=0)

for k in range(2, 10):
    from sklearn.cluster import KMeans
    labels = KMeans(n_clusters=k, n_init=5, random_state=0).fit_predict(X)
    score  = ss.compute_global(X, labels, m=300, seed=0)["global_silhouette"]
    print(f"k={k}  silhouette={score:.3f}")

A runnable version with per-cluster silhouette distribution plots is in examples/quickstart.py:

pip install silhouette-scalable matplotlib seaborn scikit-learn
python examples/quickstart.py  # after cloning the repo

Reproducing paper results

The full experiment pipeline (HDF5 datasets, cluster scripts, result aggregation) is available in the tagged research release: v1.0-paper

Metadata

Release files for silhouette-scalable 0.1.3

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

Source distribution (sdist)

Source distribution for silhouette-scalable 0.1.3
File Size Uploaded
silhouette_scalable-0.1.3.tar.gz 622.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for silhouette-scalable 0.1.3
File
silhouette_scalable-0.1.3-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
silhouette_scalable-0.1.3-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
silhouette_scalable-0.1.3-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
silhouette_scalable-0.1.3-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
silhouette_scalable-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
silhouette_scalable-0.1.3-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
silhouette_scalable-0.1.3-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
silhouette_scalable-0.1.3-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
silhouette_scalable-0.1.3-cp39-cp39-manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64 Details
silhouette_scalable-0.1.3-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details

Total release size: 2.2 MB

Release files / silhouette_scalable-0.1.3.tar.gz

Download URL silhouette_scalable-0.1.3.tar.gz
Size 622.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e51adbc73e3aa0e2afd80137ed3fa8751f1536f6b062eacf42d7903508a62a4d
BLAKE2b-256 checksum
How to use checksums
21a8d759327d1e6cd3b787d270c7693ec423682413bd808852d2125b0a388666
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL silhouette_scalable-0.1.3-cp313-cp313-manylinux_2_28_x86_64.whl
Size 224.3 kB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e7e1c9284fba149af8e5f071b72378ce39fda63a0bbe5b83163c0af82ec800bd
BLAKE2b-256 checksum
How to use checksums
bf3196c613ae3bedd24a1693c9148e41bdccc0345109ffdfe40093996c86d3c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp313-cp313-macosx_11_0_arm64.whl

Download URL silhouette_scalable-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Size 95.3 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0d64851f811d51c30ea5044376ad0cef6164524eadb217f6518cc264ed3b833b
BLAKE2b-256 checksum
How to use checksums
182540f32969d714ab30b30818f84a62239c22afa248a9ab8d1e79e82531738c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL silhouette_scalable-0.1.3-cp312-cp312-manylinux_2_28_x86_64.whl
Size 224.3 kB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f5914374c2ba81a38644135b8679ce8cab5fb338cae87aec69922c91fd2bcf9d
BLAKE2b-256 checksum
How to use checksums
d9ec3cc07143eb2c39f99573039dc3d29dffb9118a3a74f86bacc9d9485a7b46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp312-cp312-macosx_11_0_arm64.whl

Download URL silhouette_scalable-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Size 95.3 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b06f1ad9ec6fad24c36a94736920e111124f76a0a38eb89c283e6972c6e45442
BLAKE2b-256 checksum
How to use checksums
b0b5d17f1838f5ac0bf53d1072a06bbb426cc67e03616417a5448acba3bb81ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL silhouette_scalable-0.1.3-cp311-cp311-manylinux_2_28_x86_64.whl
Size 223.2 kB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
a0818285ea427d006f75e6da73e0c3881179677580b856d6ff5b577b0f8ed08a
BLAKE2b-256 checksum
How to use checksums
a067b3359c1a8ce6b560adddf472089e58a0abac11e396aac1dbc713ccaf053a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp311-cp311-macosx_11_0_arm64.whl

Download URL silhouette_scalable-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Size 93.9 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6f47b1e4bc8f188cc210b344f2d1488d9e5ab224779972903b81fe7fd85a26ef
BLAKE2b-256 checksum
How to use checksums
4a9bb1f9fca268ac16efc6d96994e33b36fbac8bafae8f0cb86beea7ba710f2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL silhouette_scalable-0.1.3-cp310-cp310-manylinux_2_28_x86_64.whl
Size 222.0 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e0a2c463769e4c1b268fcefe059d2fca36c0c5f7b3849dfb1dae32fb759920ff
BLAKE2b-256 checksum
How to use checksums
387f86a0dc4f36aa0de0158a3ad8be966b07249b9b87f9ef242754f67871ed22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp310-cp310-macosx_11_0_arm64.whl

Download URL silhouette_scalable-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Size 92.7 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b547fcd347461ab87b8d8b622f07a502eebb52645c30029362cbde2527f320ef
BLAKE2b-256 checksum
How to use checksums
ed77e04b178def350fc63553af9560d931259fd670fbe33affffcdb33464af68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp39-cp39-manylinux_2_28_x86_64.whl

Download URL silhouette_scalable-0.1.3-cp39-cp39-manylinux_2_28_x86_64.whl
Size 222.2 kB
Tags CPython 3.9 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
13bc1b7bb9ddcfa942668707d1814315562b8fd5289e48616b5785d37aa003c2
BLAKE2b-256 checksum
How to use checksums
485780e89f41edc1ea59ecfe727b49f4a4fa3e7663afafb502a1b0614aa29159
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release files / silhouette_scalable-0.1.3-cp39-cp39-macosx_11_0_arm64.whl

Download URL silhouette_scalable-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
Size 92.7 kB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e4c2985b10fa2c002444d299c55d5dcdd6e528a243d9268875222c3687fc5e12
BLAKE2b-256 checksum
How to use checksums
b15302cf75a21a2387bb23550ab727cd600a6f176da1625e0524e8fd3d8fe432
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

11 release files

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