kMeansClustering
VQ (vector quantization) of K-means clustering using Forgy's batch-mode method
Contents
Syntax
- center = kMeansClustering(data, clusterNum)
- [center, assignment, distortion, allCenter] = kMeansClustering(data, clusterNum, plotOpt)
Description
center = kMeansClustering(data, clusterNum, plotOpt) returns the centers after k-means clustering, where
- data (dim x dataNum): dataset to be clustered; where each column is a sample point
- clusterNum: number of clusters (greater than one), or matrix of columns of centers
- plotOpt: 1 for animation if the dimension is 2
- center (dim x clusterNum): final cluster centers, where each column is a center
[center, assignment, distortion, allCenter] = kMeansClustering(data, clusterNum, plotOpt) also returns assignment and distortion, where
- assignment: final assignment matrix, with assignment(i,j)=1 if data instance i belongs to cluster j
- distortion: values of the objective function during iterations
Example
DS=dcData(2); centerNum=6; plotOpt=1; [center, assignment, distortion] = kMeansClustering(DS.input, centerNum, plotOpt);
Iteration count = 1/200, distortion = 203.409106 Iteration count = 2/200, distortion = 106.740614 Iteration count = 3/200, distortion = 96.772077 Iteration count = 4/200, distortion = 94.147432 Iteration count = 5/200, distortion = 92.589887 Iteration count = 6/200, distortion = 91.721273 Iteration count = 7/200, distortion = 91.393290 Iteration count = 8/200, distortion = 91.365628 Iteration count = 9/200, distortion = 91.364346 Iteration count = 10/200, distortion = 91.364346
![](kMeansClustering_help_01.png)