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=16; plotOpt=1; [center, assignment, distortion] = kMeansClustering(DS.input, centerNum, plotOpt);
Iteration count = 1/200, distortion = 63.274343 Iteration count = 2/200, distortion = 39.763397 Iteration count = 3/200, distortion = 37.346312 Iteration count = 4/200, distortion = 36.323913 Iteration count = 5/200, distortion = 35.948277 Iteration count = 6/200, distortion = 35.826302 Iteration count = 7/200, distortion = 35.759025 Iteration count = 8/200, distortion = 35.717937 Iteration count = 9/200, distortion = 35.679391 Iteration count = 10/200, distortion = 35.659650 Iteration count = 11/200, distortion = 35.639169 Iteration count = 12/200, distortion = 35.591131 Iteration count = 13/200, distortion = 35.491004 Iteration count = 14/200, distortion = 35.451197 Iteration count = 15/200, distortion = 35.413559 Iteration count = 16/200, distortion = 35.406382 Iteration count = 17/200, distortion = 35.404516 Iteration count = 18/200, distortion = 35.404516