I'm really confused on what are the steps on how to perform k-means clustering algorithm on 1 dimension data. So suppose I have the following array of data and it should be clustered in two groups:
data = [40, 20, 30, 10, 22, 94, 66];
I have read the following site and it helped me get an idea on how to approach it but I'm still a little unsure. http://www.macwright.org/2012/09/16/k-means.html
My approach is:
- I would first calculate the mean of the entire dataset.
- then I would find calculate the euclidean distance between each point and the mean.
- then I would cluster them in to two groups, one group that had the shortest distance to mean and the other that wasn't so close.
My question is are these steps correct and how would I perform k-means clustering on the dataset if k>2. I feel like my thinking is flawed, any help would greatly appreciated.
bsxfun
for performance reasons but it should be pretty readable given the comments. $\endgroup$