{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/bandit-pam-almost-linear-time-k-medoids","title":"BanditPAM: Almost Linear Time $k$-Medoids Clustering via Multi-Armed Bandits","arxiv_id":"2006.06856","date":"2020-06-11","proceeding":null,"authors":["Mo Tiwari","Martin Jinye Zhang","James Mayclin","Sebastian Thrun","Chris Piech","Ilan Shomorony"],"abstract":"Clustering is a ubiquitous task in data science. Compared to the commonly used $k$-means clustering, $k$-medoids clustering requires the cluster centers to be actual data points and support arbitrary distance metrics, which permits greater interpretability and the clustering of structured objects. Current state-of-the-art $k$-medoids clustering algorithms, such as Partitioning Around Medoids (PAM), are iterative and are quadratic in the dataset size $n$ for each iteration, being prohibitively expensive for large datasets. We propose BanditPAM, a randomized algorithm inspired by techniques from multi-armed bandits, that reduces the complexity of each PAM iteration from $O(n^2)$ to $O(n \\log n)$ and returns the same results with high probability, under assumptions on the data that often hold in practice. As such, BanditPAM matches state-of-the-art clustering loss while reaching solutions much faster. We empirically validate our results on several large real-world datasets, including a coding exercise submissions dataset, the 10x Genomics 68k PBMC single-cell RNA sequencing dataset, and the MNIST handwritten digits dataset. In these experiments, we observe that BanditPAM returns the same results as state-of-the-art PAM-like algorithms up to 4x faster while performing up to 200x fewer distance computations. The improvements demonstrated by BanditPAM enable $k$-medoids clustering on a wide range of applications, including identifying cell types in large-scale single-cell data and providing scalable feedback for students learning computer science online. We also release highly optimized Python and C++ implementations of our algorithm.","url_abs":"https://arxiv.org/abs/2006.06856v2","url_pdf":"https://arxiv.org/pdf/2006.06856v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"bandit-pam-almost-linear-time-k-medoids","repo_url":"https://github.com/motiwari/BanditPAM-python","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"none","reach":null},{"paper_slug":"bandit-pam-almost-linear-time-k-medoids","repo_url":"https://github.com/ThrunGroup/BanditPAM","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":"clustering","task_name":"Clustering"},{"task_slug":"multi-armed-bandits","task_name":"Multi-Armed Bandits"}],"methods":[{"method_slug":"interpretability","method_name":"Interpretability"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2006.06856","atlas_url":"https://app.syntology.ai/?focus=2006.06856","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2006.06856"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/motiwari/BanditPAM-python","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ThrunGroup/BanditPAM","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":5},"by_repo_kind":{"official":{"samples":5,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":5,"samples":[{"code_sha256_prefix":"332de0baba3a0594","entry":"UCB_build","repo":"motiwari/BanditPAM-python","repo_kind":"official","path":"ucb_pam.py","file_url":"https://github.com/motiwari/BanditPAM-python/blob/HEAD/ucb_pam.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"332de0baba3a0594"}},{"code_sha256_prefix":"c7b82945e4ef5b42","entry":"UCB_build_and_swap","repo":"motiwari/BanditPAM-python","repo_kind":"official","path":"ucb_pam.py","file_url":"https://github.com/motiwari/BanditPAM-python/blob/HEAD/ucb_pam.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"c7b82945e4ef5b42"}},{"code_sha256_prefix":"0b0d49162b63c665","entry":"UCB_swap","repo":"motiwari/BanditPAM-python","repo_kind":"official","path":"ucb_pam.py","file_url":"https://github.com/motiwari/BanditPAM-python/blob/HEAD/ucb_pam.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0b0d49162b63c665"}},{"code_sha256_prefix":"e5b646c0a4cfe518","entry":"build_sample_for_targets","repo":"motiwari/BanditPAM-python","repo_kind":"official","path":"ucb_pam.py","file_url":"https://github.com/motiwari/BanditPAM-python/blob/HEAD/ucb_pam.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"e5b646c0a4cfe518"}},{"code_sha256_prefix":"6cf8d27c3d97df4e","entry":"swap_sample_for_targets","repo":"motiwari/BanditPAM-python","repo_kind":"official","path":"ucb_pam.py","file_url":"https://github.com/motiwari/BanditPAM-python/blob/HEAD/ucb_pam.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6cf8d27c3d97df4e"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}