# Why does FindClusters put closer points into different clusters?

Bug introduced in 11.3 or earlier and persisting through 12.0
Bug isn't present in version 8.0.4

I am trying to do clustering and then obtained a plot as below:-

pts = {{1, 1}, {2, 1.5}, {10, 1}, {11, 1.5}};
clts = FindClusters[pts, 2]
ListPlot[clts, PlotRange -> {{0, 12}, {0, 3}}]


As we can see, the 2 points at the left are closer to each other, but they are now put in separated clusters. Why does that happen?

If I reverse the x-y coordinate of the points, the situation is still the same (that means FindClusters is not taking priority for x-coordinates). I then tried FindClusters[pts, 2, CriterionFunction -> "CalinskiHarabasz"], the 2 closer points are still in different clusters. Finally, when I tried FindClusters[pts1, 2, DistanceFunction -> EuclideanDistance], the problem is finally solved and the 2 closer points are in the same cluster.

So I am curious: if the default distance is not the "Euclidean distance", what would that be? Why would it put the closer points into different clusters?

• Bizarre. Trace[FindClusters[pts, 2], HoldPattern[DistanceFunction -> _]] shows a lot of DistanceFunction -> EuclideanDistance, so FindClusters appears to be using EuclideanDistance as default. – JungHwan Min Jun 12 '18 at 21:57
• Works for me: imgur.com/a/RyTK78l – corey979 Jun 12 '18 at 22:13
• In this case, FindClusters internally uses MachineLearningPackageScopeAutomaticDistanceFunction[Automatic][{"Numerical", "Numerical"}] as its distance function, which evaluates to EuclideanDistance. Huh. – JungHwan Min Jun 12 '18 at 22:17
• What OS and version of Mathematica are you using? The code doesn't seem to use EuclideanDistance on Mathematica versions 11.1.1 and 11.2.0 on Windows, and 11.3.0 on Linux. – JungHwan Min Jun 12 '18 at 22:24
• I observe the same with version 11.3 on Windows 7 x64. Looks like a bug, worth reporting. Version 8.0.4 gives the expected result. – Alexey Popkov Jun 13 '18 at 11:13

When using FindClusters or ClusterClassify there is some preprocessing going on that might change your data. In this case, if you compute

 c = ClusterClassify[pts, 2]


anche check for c[[1]] you will see that the data gets standardized first. To prevent the function to do that it is enough to specify a DistanceFunction.

When doing it you get the expected answer:

pts = {{1, 1}, {2, 1.5}, {10, 1}, {11, 1.5}};
clts = FindClusters[pts, 2, DistanceFunction -> EuclideanDistance]

{{{1, 1}, {2, 1.5}}, {{10, 1}, {11, 1.5}}}

• "there is some preprocessing going on that might change your data" - isn't it a bug? Preprocessing must not change the input data! – Alexey Popkov Oct 29 '19 at 15:47