5
$\begingroup$

I run into this problem when analyzing data with obvious clusters. Why doesn't Mathematica find the four clusters?

stat = RandomChoice[{{0, 0, 0}, {1, 0, 0}, {1, 1, 1}, {0, 0, 1}},1000];
clu = FindClusters[stat];
mclu = Map[Mean, clu]

{{1, 0, 0}, {16/33, 16/33, 1}, {0, 0, 0}}

clu = FindClusters[stat, 4];
mclu = Map[Mean, clu]

{{1, 0, 0}, {120/247, 120/247, 1}, {0, 0, 0}, {0, 0, 1}}

$\endgroup$
2
  • 1
    $\begingroup$ What's your version? it works perfectly fine on my computer~ $\endgroup$
    – Wjx
    Aug 31, 2016 at 23:26
  • $\begingroup$ I use version 9.0.1.0 $\endgroup$ Sep 2, 2016 at 8:31

1 Answer 1

5
$\begingroup$

The problem may be the Method of clustering, that is, the clustering algorithm. Although it isn't immediately obvious from the Mathematica documentation, the default method may be incremental or local, where points are assigned to clusters as they are sequentially considered or in small batches.

Thus for instance, if the first two points are {0,0,0} and {0,0,1} they may be considered by the algorithm to be a single cluster, and updated accordingly.

If you use Method -> "Agglomerate" this problem vanishes.

Likewise, if you first Sort the data, this problem vanishes:

stat = RandomChoice[{{0, 0, 0}, {1, 0, 0}, {1, 1, 1}, {0, 0, 1}}, 
   1000];
clu = FindClusters[Sort[stat], 4];
mclu = Map[Mean, clu]

(* {{0, 0, 0}, {0, 0, 1}, {1, 0, 0}, {1, 1, 1}} *)

$\endgroup$
5
  • $\begingroup$ Yes... that's what I stated and coded, but didn't paste the proper code. Now my answer is fixed. Thanks. $\endgroup$ Aug 31, 2016 at 23:53
  • 1
    $\begingroup$ Agglomerate works but only if you enter the number of clusters in advance. Sort fails to help at least for me. Make the data slightly more complicated by adding a few stray values and agglomerate fails as well when a stray value gets its own tiny cluster. $\endgroup$ Sep 2, 2016 at 9:14
  • $\begingroup$ @Mats Lijendahl Really? You run the (Sort) code I posted and don't get the output I posted? Then I have no idea what might cause such a problem. $\endgroup$ Sep 2, 2016 at 17:30
  • $\begingroup$ Yes really. I double checked. May it be that I use version 9? $\endgroup$ Sep 2, 2016 at 21:56
  • $\begingroup$ I'm using version 10.0.4, but that "explains" nothing... $\endgroup$ Sep 3, 2016 at 0:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.