# K-中心点

K-中心点是一种划分聚类方法，其中每个簇由一个中心点代表——中心点是一个实际观测到的数据点，选取它是为了最小化其与簇内其他成员之间相异度之和。由于中心必须是真实的观测值，且目标函数是相异度之和而非欧几里得距离平方和，该方法适用于任意相异度度量，并且比k-均值对噪声和离群点更具鲁棒性——k-均值的算术均值中心不必对应任何数据点，且会被极端值拉偏。<sup>[1](https://www.sciencedirect.com/science/article/pii/S2665963826000230)</sup><sup> • </sup><sup>[2](https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 簇中心 | 中心点是观测到的数据点，即与其簇内所有其他对象相异度最小的对象；这种中心性概念适用于任意相似度或相异度度量。<sup>[3](https://arxiv.org/abs/1810.05691)</sup> |
| 目标 | 寻找簇分配，使 \( \sum_{h=1}^k \sum_{i \in h} d_{i,h_c} \) 最小，即每个点到其簇代表中心的距离之和。<sup>[4](https://lanselin.github.io/introbook_vol2/kmedoids.html)</sup> |
| 起源 | PAM（围绕中心点的划分），由Leonard Kaufman和Peter J. Rousseeuw于1987年提出，在《Finding Groups in Data》（1990）中描述。<sup>[5](https://www.dei.unipd.it/~capri/DM/MATERIALE/Clustering1617.pdf)</sup><sup> • </sup><sup>[6](https://www3.cs.stonybrook.edu/~cse521/ch7book.pdf)</sup> |
| 开销 | PAM将所有成对相异度存储在一个O(n²)矩阵中，导致O(n²)的内存需求；scikit-learn-extra的KMedoids同样具有O(n_samples²)的空间复杂度。<sup>[7](https://sites.stat.washington.edu/wxs/Stat592-w2011/Literature/struyf-hubert-rousseeuw-clustering-object-oriented-1997.pdf)</sup><sup> • </sup><sup>[8](https://scikit-learn-extra.readthedocs.io/en/latest/generated/sklearn_extra.cluster.KMedoids.html)</sup><sup> • </sup><sup>[21](https://stat.ethz.ch/R-manual/R-patched/library/cluster/html/pam.html)</sup> |
| 大数据变体 | CLARA对数据样本进行聚类；CLARANS使用随机搜索；FasterPAM将交换阶段加速O(k)倍；BanditPAM将每次迭代从O(n²)降至O(n log n)。<sup>[9](https://www.researchgate.net/profile/Peter-Rousseeuw/publication/220695963_Finding_Groups_in_Data_An_Introduction_To_Cluster_Analysis/links/60fbbe85169a1a0103b20e91/Finding-Groups-in-Data-An-Introduction-To-Cluster-Analysis.pdf)</sup><sup> • </sup><sup>[10](https://sigmod.org/publications/dblp/db/conf/vldb/vldb94-144.html)</sup><sup> • </sup><sup>[3](https://arxiv.org/abs/1810.05691)</sup><sup> • </sup><sup>[11](https://arxiv.org/abs/2006.06856)</sup> |
| 鲁棒性 | 基于中心点的方法（如PAM和CLARA）由于中心是实际数据点，对离群点的鲁棒性高于基于均值的方法。<sup>[12](https://journals.sagepub.com/doi/10.1177/20552076261486967)</sup> |

## PAM算法

经典的k-中心点算法是PAM，由布鲁塞尔自由大学的统计学家Leonard Kaufman和当时在安特卫普大学机构的Peter J. Rousseeuw在他们1990年的著作《Finding Groups in Data: An Introduction to Cluster Analysis》中发表。<sup>[6](https://www3.cs.stonybrook.edu/~cse521/ch7book.pdf)</sup><sup> • </sup><sup>[13](https://onlinelibrary.wiley.com/doi/10.1002/9780470316801.ch3)</sup> PAM在观测中搜索k个代表对象，即中心点。找到一组k个中心点后，它将每个观测分配到最近的中心点，从而构建k个簇，寻求使观测到其最近代表的相异度之和最小的代表集。<sup>[2](https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.html)</sup>

**构建与交换阶段。** 默认情况下，PAM首先寻找一组良好的初始中心点（构建阶段），然后寻找目标函数的局部极小值——即这样一种解：将任一观测与一个中心点进行单次交换都不会降低目标函数值；这就是交换阶段。<sup>[2](https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.html)</sup> 构建步骤是原始PAM算法中使用的贪心初始化，scikit-learn-extra将其作为`init`选项之一暴露出来，与`random`、`heuristic`（到所有其他点距离之和最小的k个点）以及`k-medoids++`（k-means++的改编版，通常能产生更分散的初始中心点）并列。<sup>[8](https://scikit-learn-extra.readthedocs.io/en/latest/generated/sklearn_extra.cluster.KMedoids.html)</sup>

**该方法接受什么。** 与k-均值相比，R实现`pam`接受相异度矩阵作为输入，最小化相异度之和而非欧几里得距离平方和，并提供轮廓图——一种图形显示，还支持通过平均轮廓宽度选择簇的数量。<sup>[2](https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.html)</sup>

## 扩展到大数据

PAM对所有成对相异度的穷举搜索使其不适用于大型数据集：完整的相异度矩阵在内存中有O(n²)个条目，计算时间的增长至少同样快。因此Kaufman和Rousseeuw构建了CLARA（大型应用聚类），首次描述于1986年，它从数据中抽取样本，用PAM算法将其聚类为k个子集，并将样本外的每个对象分配到k个代表对象中最近的一个。在若干次抽样后（原始描述中为五次），保留平均距离最低的样本。<sup>[7](https://sites.stat.washington.edu/wxs/Stat592-w2011/Literature/struyf-hubert-rousseeuw-clustering-object-oriented-1997.pdf)</sup><sup> • </sup><sup>[9](https://www.researchgate.net/profile/Peter-Rousseeuw/publication/220695963_Finding_Groups_in_Data_An_Introduction_To_Cluster_Analysis/links/60fbbe85169a1a0103b20e91/Finding-Groups-in-Data-An-Introduction-To-Cluster-Analysis.pdf)</sup> R的`clara`函数通过在固定大小的子数据集上工作，使时间和存储需求与n成线性而非二次关系，且每个新的子数据集被强制包含迄今为止最佳子数据集中找到的中心点。<sup>[14](https://rweb.stat.umn.edu/R/library/cluster/html/clara.html)</sup> 抽样的弱点在于，对有偏样本的良好聚类不一定代表对整个数据集的良好聚类。<sup>[6](https://www3.cs.stonybrook.edu/~cse521/ch7book.pdf)</sup>

CLARANS由[不列颠哥伦比亚大学](https://www.edgepedia.org/zh/university-of-british-columbia)的Raymond T. Ng和西蒙弗雷泽大学的Jiawei Han在1994年VLDB上提出，它用对中心点集空间的随机搜索替代抽样，是为空间数据挖掘开发的，实验表明它与现有聚类方法相比是高效的。<sup>[10](https://sigmod.org/publications/dblp/db/conf/vldb/vldb94-144.html)</sup><sup> • </sup><sup>[15](https://rmarcus.info/dbscholar/papers/h781510ef8e55d9a1)</sup>

## 更快的交换算法

交换阶段主导了PAM的运行时间。多特蒙德工业大学的Erich Schubert和Peter J. Rousseeuw提出了修改方案，在交换阶段实现O(k)倍的加速，同时找到与原始算法相同的结果；通过稍微放宽交换的选择，每次迭代最多可执行k次交换，质量相当。在k = 100的真实数据实验中，他们观察到比原始PAM的交换阶段快200倍，而在k = 2时新的交换阶段仅快1.5倍，因为加速比随k增长。<sup>[3](https://arxiv.org/abs/1810.05691)</sup> R的`pam`函数通过其`pamonce`和`variant`选项实现了这些思想：FastPAM变体利用一个点不可能同时最接近所有当前中心点这一事实，将运行时间减少O(k)倍，而FasterPAM立即执行每个改进交换，运行时间为O(n²)而非O(n(n−k)k)。FasterPAM还用随机初始化替代构建阶段以避免O(n²k)的构建开销，这对大k来说快得多，同时保持相似的结果质量。<sup>[2](https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.html)</sup>

BanditPAM由Mo Tiwari及其同事在NeurIPS 2020上发表，走了不同的路线：一种受多臂老虎机启发的随机算法，将每次PAM迭代的复杂度从O(n²)降至O(n log n)，在实践中通常成立的数据假设下以高概率返回相同的结果。在包括[Code.org](https://www.edgepedia.org/zh/code-org)编码练习语料库、10x Genomics 68k PBMC单细胞RNA测序数据集和MNIST在内的真实数据集上，它达到了与最先进方法相当的聚类损失，同时运行速度快至4倍，距离计算次数最多可降至原来的1/200。<sup>[11](https://arxiv.org/abs/2006.06856)</sup>

## 实现与实践

K-中心点在标准统计和机器学习环境中均可使用。R的`cluster`包提供`pam`和`clara`，其中`pam`在实践中受限于其O(n²)的内存和时间需求以及n ≤ 65536个观测的硬限制，超过此限制则`clara`更可取。<sup>[2](https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.html)</sup> Python包scikit-learn-extra提供`KMedoids`，默认值为`n_clusters=8`、欧几里得度量、`alternate`方法（更快，而`pam`更准确）、`heuristic`初始化和`max_iter=300`；它也接受预计算的距离矩阵代替设计矩阵。<sup>[8](https://scikit-learn-extra.readthedocs.io/en/latest/generated/sklearn_extra.cluster.KMedoids.html)</sup> ELKI数据挖掘软件包含PAM和FasterPAM实现。<sup>[16](https://elki-project.github.io/releases/release0.8.0/javadoc/elki/clustering/kmedoids/PAM.html)</sup>

由于k-中心点适用于任意相异度，它被用于[欧几里得几何](https://www.edgepedia.org/zh/euclidean-geometry)不适用的情况，例如生物学等领域中的Jaccard、Gower或更复杂的距离，以及结合Jaccard、Hamming、Gower和Manhattan等度量的临床聚类研究中的混合类型数据。<sup>[3](https://arxiv.org/abs/1810.05691)</sup><sup> • </sup><sup>[17](https://pmc.ncbi.nlm.nih.gov/articles/PMC9017600/)</sup> He Jiang和Ery Arias-Castro 2021年的理论结果建立了k-中心点在度量空间中的一致性，并表明在包括广泛损失函数选择的一般条件下，k-中心点渐近等价于限制在底层分布支撑集上的k-均值。<sup>[18](https://proceedings.mlr.press/v130/jiang21c.html)</sup>

## 与k-均值的比较

在欧几里得几何中，k-均值所使用的均值是簇中心的良好估计量，但对于任意相异度不存在这样的均值，这就是改用中心点的原因。<sup>[3](https://arxiv.org/abs/1810.05691)</sup> 大型数据集上的评估报告称，k-中心点在执行时间方面更好，对离群点不敏感，并且与k-均值相比减少了噪声，因为它最小化的是数据对象的相异度之和而非平方和。<sup>[19](https://www.sciencedirect.com/science/article/pii/S1877050916000971)</sup> 代价是成对距离计算：k-中心点需要数据点之间的成对相似度或距离矩阵，这对大型数据集可能过于昂贵，而这一开销正是CLARA、FasterPAM和BanditPAM系列工作所解决的。<sup>[20](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0162259)</sup>

## References

1. [kmed: An R package for reproducible distance-based k-medoids clustering, Software Impacts](https://www.sciencedirect.com/science/article/pii/S2665963826000230)
2. [pam {cluster}, R Documentation](https://stat.ethz.ch/R-manual/R-devel/library/cluster/html/pam.html)
3. [Schubert, E. and Rousseeuw, P.J. Faster k-Medoids Clustering: Improving the PAM, CLARA, and CLARANS Algorithms, arXiv:1810.05691](https://arxiv.org/abs/1810.05691)
4. [K-Medoids, An Introduction to Spatial Data Science with GeoDa](https://lanselin.github.io/introbook_vol2/kmedoids.html)
5. [Partitioning Around Medoids (PAM) algorithm, University of Padova course notes](https://www.dei.unipd.it/~capri/DM/MATERIALE/Clustering1617.pdf)
6. [PAM (Partitioning Around Medoids) (1987), Stony Brook course notes](https://www3.cs.stonybrook.edu/~cse521/ch7book.pdf)
7. [Struyf, A., Hubert, M. and Rousseeuw, P.J. (1997). Clustering in an Object-Oriented Environment](https://sites.stat.washington.edu/wxs/Stat592-w2011/Literature/struyf-hubert-rousseeuw-clustering-object-oriented-1997.pdf)
8. [sklearn_extra.cluster.KMedoids, scikit-learn-extra documentation](https://scikit-learn-extra.readthedocs.io/en/latest/generated/sklearn_extra.cluster.KMedoids.html)
9. [Kaufman, L. and Rousseeuw, P.J. (1990). Clustering Large Applications (Program CLARA), in Finding Groups in Data](https://www.researchgate.net/profile/Peter-Rousseeuw/publication/220695963_Finding_Groups_in_Data_An_Introduction_To_Cluster_Analysis/links/60fbbe85169a1a0103b20e91/Finding-Groups-in-Data-An-Introduction-To-Cluster-Analysis.pdf)
10. [Ng, R.T. and Han, J. (1994). Efficient and Effective Clustering Methods for Spatial Data Mining, VLDB '94, 144–155](https://sigmod.org/publications/dblp/db/conf/vldb/vldb94-144.html)
11. [Tiwari, M. et al. (2020). BanditPAM: Almost Linear Time k-Medoids Clustering via Multi-Armed Bandits, arXiv:2006.06856](https://arxiv.org/abs/2006.06856)
12. [Orooji, A. et al. (2026). A methodological study of clustering evaluation in medical data, SAGE Open Medicine](https://journals.sagepub.com/doi/10.1177/20552076261486967)
13. [Kaufman, L. and Rousseeuw, P.J. (1990). Clustering Large Applications (Program CLARA), Wiley](https://onlinelibrary.wiley.com/doi/10.1002/9780470316801.ch3)
14. [clara {cluster}, R Documentation](https://rweb.stat.umn.edu/R/library/cluster/html/clara.html)
15. [Efficient and Effective Clustering Methods for Spatial Data Mining, paper summary](https://rmarcus.info/dbscholar/papers/h781510ef8e55d9a1)
16. [PAM, ELKI javadoc](https://elki-project.github.io/releases/release0.8.0/javadoc/elki/clustering/kmedoids/PAM.html)
17. [Simulation-derived best practices for clustering clinical data, PMC](https://pmc.ncbi.nlm.nih.gov/articles/PMC9017600/)
18. [Jiang, H. and Arias-Castro, E. (2021). On the Consistency of Metric and Non-Metric K-Medoids, AISTATS, PMLR 130:2485–2493](https://proceedings.mlr.press/v130/jiang21c.html)
19. [Analysis of K-Means and K-Medoids Algorithm For Big Data, Procedia Computer Science 78 (2016), 507–512](https://www.sciencedirect.com/science/article/pii/S1877050916000971)
20. [What to Do When K-Means Clustering Fails: A Simple yet Principled Alternative Algorithm, PLOS One](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0162259)
21. [R: Partitioning Around Medoids](https://stat.ethz.ch/R-manual/R-patched/library/cluster/html/pam.html)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Machine learning methods › Supervised, unsupervised, and semi-supervised learning › Clustering algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/k-medoids

English original: https://www.edgepedia.org/k-medoids
