Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201919

Why doesn't kmeans find the 3 clusters?

$
0
0

I run a kmeans on a 3 dimensional dataset and get the following result: 3D Plotting of the data set coloured based on clusters

Code as followed:

library(tidyr)

setwd('C:/temp/rwd')
getwd()

df <- read.table('data-1581352459203.csv', 
                 header = TRUE,
                 sep = ",")

dff <- df %>% pivot_wider(names_from = SensorId, values_from = last)

data = data.frame(dff$`3`, dff$`4`, dff$`5`)
cf.kmeans <- kmeans(data, centers = 3, nstart = 20)
cf.kmeans

library(plot3D)
x <- dff$`3`
y <- dff$`4`
z <- dff$`5`
scatter3D(x, y, z, 
          bty ="g", pch = cf.kmeans$cluster, colvar=as.numeric(cf.kmeans$cluster),
          xlab = "Temperature", ylab = "Humidity", zlab = "Speed",
          ticktype = "detailed")

library("plot3Drgl")
plotrgl()

Dataset looks like this (90 observations):

enter image description here

I would very much appreciate an explanation why kmeans does not find the obvious clusters.


Viewing all articles
Browse latest Browse all 201919

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>