{"id":34096392,"url":"https://github.com/hugo-strang/silhouette-upper-bound","last_synced_at":"2025-12-14T15:35:20.360Z","repository":{"id":296215964,"uuid":"992239971","full_name":"hugo-strang/silhouette-upper-bound","owner":"hugo-strang","description":"An upper bound of the Average Silhouette Width.","archived":false,"fork":false,"pushed_at":"2025-11-06T16:15:43.000Z","size":905,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-06T18:16:51.029Z","etag":null,"topics":["cluster-analysis","clustering","clustering-evaluation","data-mining","data-science","machine-learning","python","python3","silhouette-coefficient","silhouette-score","upper-bound"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/silhouette-upper-bound/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hugo-strang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-05-28T20:54:01.000Z","updated_at":"2025-11-06T16:15:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"baad1fa1-1512-4747-8625-394d63cd005f","html_url":"https://github.com/hugo-strang/silhouette-upper-bound","commit_stats":null,"previous_names":["hugo-strang/silhouette-upper-bound"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hugo-strang/silhouette-upper-bound","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugo-strang%2Fsilhouette-upper-bound","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugo-strang%2Fsilhouette-upper-bound/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugo-strang%2Fsilhouette-upper-bound/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugo-strang%2Fsilhouette-upper-bound/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hugo-strang","download_url":"https://codeload.github.com/hugo-strang/silhouette-upper-bound/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugo-strang%2Fsilhouette-upper-bound/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27730560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-14T02:00:11.348Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cluster-analysis","clustering","clustering-evaluation","data-mining","data-science","machine-learning","python","python3","silhouette-coefficient","silhouette-score","upper-bound"],"created_at":"2025-12-14T15:35:15.213Z","updated_at":"2025-12-14T15:35:20.352Z","avatar_url":"https://github.com/hugo-strang.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Tests](https://github.com/hugo-strang/silhouette-upper-bound/actions/workflows/tests.yml/badge.svg?branch=main)\n\n# Silhouette Upper Bound\nAn upper bound of the [Average Silhouette Width](https://en.wikipedia.org/wiki/Silhouette_(clustering)).\n\n![Silhouette Samples](figures/silhouette_samples.png)\n*Figure 1: Kmeans clustering applied to a synthetic dataset. Code available [`here`](./experiments/figure_silhouette_samples.py).*\n\n![ASW vs K](figures/asw_vs_k.png)\n*Figure 2: ASW for varying K. Code available [`here`](./experiments/figure_asw_vs_k.py).*\n\n## Overview\nEvaluating clustering quality is a fundamental task in cluster analysis, and the\n[Average Silhouette Width](https://en.wikipedia.org/wiki/Silhouette_(clustering)) (ASW) is one of the most widely used metrics for this purpose. ASW scores range from $-1$ to $1$, where:\n\n* Values near 1 indicate well-separated, compact clusters\n\n* Values around 0 suggest overlapping or ambiguous cluster assignments\n\n* Values near -1 imply that many points may have been misassigned\n\nOptimizing the Silhouette score is a common objective in clustering workflows. However, since we rarely know the true global ASW-maximum achievable for a dataset, it's difficult to assess how close a given clustering result is to being globally optimal. Simply comparing to the theoretical maximum of 1 is often misleading, as the structure of the dataset imposes inherent limits on what is achievable.\n\nThis project introduces a data-dependent upper bound on the ASW that hopefully can provide a more meaningful reference point than the fixed value of 1. The upper bound helps answer a key question: How close is my clustering result to the best possible outcome on this specific data?\n\nTo compute the upper bound, the method requires a dissimilarity matrix as input.\n\nYou can find more details in this arXiv [preprint](https://arxiv.org/abs/2509.08625).\n\n## Use Cases\n\nThe proposed data-dependent upper bound on the Average Silhouette Width (ASW) opens up opportunities for both research and industry applications.\n\n### Research (Academic Endeavors)\n\n**Confirming global optimality:** Certify that an empirically obtained clustering is within $\\epsilon$ of the true ASW maximum.\n\n**Sharper comparisons across algorithms:** Interpret algorithm performance relative to dataset-specific ceilings, rather than the generic $[-1,1]$ scale.\n\n### Industry (Practical Applications)\n\n**Early stopping in optimization loops:** Halt ASW-based searches once solutions are provably close to optimal, saving time and resources.\n\n**Proxy for clusterability:** A low bound indicates limited potential for meaningful clusters, guiding analysts before heavy computation.\n\n**Outlier detection:** Pointwise upper bounds flag observations that cannot fit well into any cluster.\n\n**Constraint-aware clustering:** Incorporate application constraints (e.g. minimal cluster size) via restricted bounds.\n\n### Extension to other clustering quality measures\nIn practical scenarios where clusters are imbalanced and small groups also matter, the so called *macro-averaged silhouette* (see [this article](https://arxiv.org/abs/2401.05831)) might be more favorable compared to the standard ASW. The macro-silhouette averages first at the cluster level and then across clusters. \n\nIn this project we implement an upper bound of this silhouette variant in a solution space that is constrained by fixed cluster sizes.\n\n\n## Installation\n```\npip install silhouette-upper-bound\n```\n\n## Examples\n\nTo help you get started, we provide example scripts demonstrating common use cases.\nYou can find these in the [`demos/`](./demos) folder.\n\n## Quickstart\n```python\nimport numpy as np\nfrom silhouette_upper_bound import upper_bound\n\nif __name__ == '__main__':\n\n    np.random.seed(42)\n\n    # dummy data\n    A = np.random.rand(100, 100)\n    D = (A + A.T) / 2\n    np.fill_diagonal(D, 0)\n\n    # ASW upper bound\n    ub = upper_bound(D)\n\n    print(f\"There is no clustering of the data points of D that has a higher Silhouette score than {ub}.\")\n```\n\n## Experimental results\n\nWe evaluate the performance of the upper bound using synthetic datasets generated with `scikit-learn`’s `make_blobs()` [function](https://scikit-learn.org/stable/modules/generated/sklearn.datasets.make_blobs.html). Each dataset is identified by a label of the form `n_samples`-`n_features`-`centers`-`cluster_std`, which corresponds to the parameters used in the data generation.\n\nThe code that generates the results below can be found in \n[`experiments/`](./experiments/table_asw_synthetic_data.py).\n\n| Dataset | KMeans ASW | ASW upper bound | Worst-case relative error |\n| --- | --- | --- | --- |\n| 400-64-5-6 | 0.249 | 0.376 | 0.38 |\n| 400-64-2-2 | 0.673 | 0.673 | .00 |\n| 400-128-7-3 | 0.522 | 0.566 | 0.08 |\n| 1000-161-2-13 | 0.084 | 0.182 | 0.54 |\n\nNote that the upper bound confirms global optimality for KMeans on dataset 400-64-2-2.\n\nMore comprehensive results on synthetic datasets are available in [`results/`](./results/).\n\n## Contribution\n\nContributions are welcome! If you have suggestions for improvements, bug reports, or new features, feel free to open an issue or submit a pull request.\n\nTo contribute:\n\n1. Fork the repository.\n2. Create a new branch for your feature or fix.\n3. Submit a pull request.\n\nThank you for helping improve this project!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugo-strang%2Fsilhouette-upper-bound","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugo-strang%2Fsilhouette-upper-bound","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugo-strang%2Fsilhouette-upper-bound/lists"}