MichaelChirico / r-bugs

A ⚠️read-only⚠️mirror of https://bugs.r-project.org/
20 stars 0 forks source link

[BUGZILLA #16623] k-means() fails if centers has only one center #6010

Open MichaelChirico opened 4 years ago

MichaelChirico commented 4 years ago

AFAICS, the k-means method should with a single center (and I am able to run the following command):

(Using Iris dataset as an example)

kmeans(rewires, centers = 1)

K-means clustering with 1 clusters of sizes 150

Cluster means: Sepal.Length Sepal.Width Petal.Length Petal.Width 1 5.843333 3.057333 3.758 1.199333

Clustering vector: [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [66] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 [131] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Within cluster sum of squares by cluster: [1] 681.3706 (between_SS / total_SS = 0.0 %)

... However, when a single center is provided instead, kmeans fails with an error. Verified using the centers generated by above command.

x<-kmeans(rewires, centers=1)
x<-kmeans(newiris, centers=x$centers)

Error: number of cluster centres must lie between 1 and nrow(x)

The same error is not seen for nrows(centers) > 1.


METADATA

MichaelChirico commented 4 years ago

yes, that behaviour is wrong .... even though not encountered much in practice.

I will fix this for R-devel (and R-patched), so this fix will be in the next release of R... almost surely not in 2015 anymore, as today R 3.2.3 has been released.


METADATA