Following my posted data here, I conducted a k-mean clustering analysis. I refereed to this post: How to produce a pretty plot of the results of k-means cluster analysis? for the clusters visualization

# Read and Sort Input Data
mydata <- read.csv(file="three_county_6_25.csv", head=TRUE, sep=",") # read input data
mydata2 <- scale(mydata)  # Normalize the data

# Determine number of clusters
nc <- NbClust(mydata2, min.nc=2, max.nc=15, method="kmeans")

# Do K-means clustering
fit.km <- kmeans(mydata2, centers = 3, nstart=25)

 # Visualize the clusters
 # Fig 1
 plotcluster(mydata2, fit.km$cluster)
 # Fig 2
 clusplot(mydata2, fit.km$cluster, color=TRUE, shade=TRUE,labels=2, lines=0)
 # Fig 3
 with(mydata, pairs(mydata2, col=c(1:3)[fit.km$cluster]))

The NbClust indicates 2 clusters: enter image description here

Here are the visualization of clusters:enter image description here

I am not sure how to interpret the clusters visualization result. 1) The 1st cluster plot is doing "Centroid Plot against 1st 2 discriminant functions". It seemed the clusters showed three groups. 2) The 2nd cluster plot "vary parameters for most readable graph" (referred from Quick-R: Cluster Analysis).


1 Answer 1


The data contains correlations.

k-means cannot handle correlations, and failed badly.

Either split your data manually based on the visualization (the left looks reasonable), or use a different algorithm capable of handling linear elongated clusters.

  • 1
    $\begingroup$ Do you think if I do PCA on the data, then do k-means on the PCs, will that solve the correlation problems? I saw a post indicated this solution: stats.stackexchange.com/questions/92985/… $\endgroup$
    – enaJ
    Commented Jun 26, 2015 at 18:01
  • 2
    $\begingroup$ Sometimes. Sometimes not. Visualize again, and check if A) the results look much better in the visualization, and B) the plot exhibits a real elbow. No elbow in the plot usually indicates that kmeans didn't work. $\endgroup$ Commented Jun 26, 2015 at 20:22
  • 1
    $\begingroup$ Also, could you guide me to understand why the correlation will fail k-means? I did a quick search, but don't have the fortune to find the exact answer: stats.stackexchange.com/search?q=k+mean+correlation $\endgroup$
    – enaJ
    Commented Jun 26, 2015 at 21:27
  • $\begingroup$ Correlation roughly means scaling one axis, but not another. K-means is very sensitive to rescaling axes differently. $\endgroup$ Commented Jun 26, 2015 at 22:05

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.