Matlab k mean clustering result is not appriacte

I have a data sets which has two columns. I am trying to apply k mean clustering but result does not satisfy me. What i see with my naked eye is better than the clustering result so is there anyway to improve my clustering. Here is the data without clustering. I can basically see three clusters

When i apply k mean clustering with the following code i get the below result which does not make a sense. I think red and green should be in the same cluster and the blue should be separated from ~200 (on the x-axis).

opts = statset('Display','final'); [idx,C] = kmeans(wpf,3,'Distance','sqeuclidean',... 'Replicates',10,'Options',opts); k_mean=figure; plot(wpf(idx==1,1),wpf(idx==1,2),'r.','MarkerSize',12) hold on plot(wpf(idx==2,1),wpf(idx==2,2),'b.','MarkerSize',12) plot(wpf(idx==3,1),wpf(idx==3,2),'g.','MarkerSize',12) legend('Cluster 1','Cluster 2','Cluster 3',... 'Location','NW')

I need you guys help. If you are interested, i can also provide raw data sets.

• Have you tried performing multiple kmeans runs? It's very sensitive to the starting centroids, which are randomly initiated. – ilanman Nov 2 '16 at 15:15
• I think this part " 'Replicates',10" in my above code performing multiple k-means runs – Cagatay Yilmaz Nov 7 '16 at 6:36

First of all, k-means is sensitive to scaling. Your x axis has a much larger scale than your y axis. Try looking at an undistorted image to understand what is happening. Imagine stretching your image 7x on the x-axis, would you still recognize the same clusters?

Beware that results will non-comparable attributes are usually not very reliable. So even if you scale your data, the results may be unpredictable (when your data changes) or statistically questionable.

Consider using Gaussian Mixture Modeling rather than k-means, or DBSCAN, because these are density-based clusters.

After standardizing your data, and using DBSCAN with eps=0.14 and minpts=50, I get for example this result (I chose eps based on the OPTICS plot):

But as expected, EM works better here. In particular once you choose four clusters, because apparently the right one are two overlapping clusters; one with little covariance, and one with negative covariance.

It's worth also looking at the histograms, or a kernel density plot. Because the cluster on the left is very thin compared to the others, i.e. the data is rather unbalanced. I used ELKI for these experiments.

• i could not figure out how to apply dbscan because of its user defined inputs such as eps and minpts. Can you show me how to do that if possible? Again if you want i can provide raw data. – Cagatay Yilmaz Nov 7 '16 at 11:32
• Imcertainly can't without data... – Anony-Mousse Nov 7 '16 at 20:40
• how can i send the data? the data is txt file. – Cagatay Yilmaz Nov 8 '16 at 13:09
• Either way, load it into ELKI, try EM with k=3. – Anony-Mousse Nov 8 '16 at 20:25
• Here is the link for my data myweb.sabanciuniv.edu/cagatayyilmaz/files/2013/08/myFile.txt – Cagatay Yilmaz Nov 9 '16 at 9:48