Main Content

k-Means and k-Medoids Clustering

Cluster by minimizing mean or medoid distance, and calculate Mahalanobis distance

k-means and k-medoids clustering partitions data into k number of mutually exclusive clusters. These techniques assign each observation to a cluster by minimizing the distance from the data point to the mean or median location of its assigned cluster, respectively. Mahalanobis distance is a unitless metric computed using the mean and standard deviation of the sample data, and accounts for correlation within the data.

Live Editor Tasks

Cluster DataCluster data using k-means or hierarchical clustering in the Live Editor (Since R2021b)

Functions

expand all

kmeansk-means clustering
kmedoidsk-medoids clustering
mahalMahalanobis distance to reference samples
incrementalKMeans Incremental k-means clustering (Since R2025a)
fitFit principal component analysis model to streaming data (Since R2024a)
assignClustersAssign observations to existing clusters (Since R2025a)
updateMetricsUpdate performance metrics in incremental k-means clustering model given new data (Since R2025a)
resetReset incremental k-means clustering model (Since R2025a)
incrementalDynamicKMeans Incremental dynamic k-means clustering (Since R2025a)
fitTrain model for incremental dynamic k-means clustering (Since R2025a)
assignClustersAssign observations to existing clusters and dynamic clusters (Since R2025a)
updateMetricsUpdate performance metrics in incremental dynamic k-means clustering model given new data (Since R2025a)
resetReset incremental dynamic k-means clustering model (Since R2025a)

Topics