代码如下:
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()
数据集如下所示(90 个观察值):
我非常感谢解释为什么 kmeans 没有找到明显的集群。