首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多元k-均值聚类

多元k-均值聚类
EN

Stack Overflow用户
提问于 2014-12-11 01:21:00
回答 1查看 986关注 0票数 0

我试着用r做一个多元k均值聚类图,我有3个变量,10列数据,加上上下文(就像Iris的物种),所以有11个变量。很明显,我的x是PeruReady

根据我在网上的一篇教程,我得到了以下结论:

代码语言:javascript
复制
PeruReady.km <- kmeans(PeruReady[, -1], 3, iter.max=1000) 
tbl <- table(PeruReady[, 1], PeruReady.km$cluster) 
PeruReady.dist <- dist(PeruReady[, -1]) 
PeruReady.mds <- cmdscale(PeruReady.dist) 
c.chars <- c("*", "o", "+")[as.integer(PeruReady$Context)] 
a.cols <- rainbow(3)[PeruReady$cluster] 
plot(PeruReady.mds, col=a.cols, pch=c.chars, xlab="X", ylab="Y")

但是我的图完全是空的,我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2015-04-26 20:23:08

使用一个很小的数据集(demand.sm),您的代码就可以正常工作。你的所有数值列都规范化了吗?

代码语言:javascript
复制
dput(demand.sm) 

structure(list(Demand = c("rify la", "p quasi", "rify LD", "ventive", 
"ekeeper", " de min", " risk g", " approv", "uest te", "", "al trai", 
"cation", "ely inv", "rge tim", "get of ", "vey pro", "ent ONA", 
"ble sel", "cipline", "tus rep", "ced-ran"), normalized = structure(c(-1.15780226157481, 
-0.319393727330983, -1.15780226157481, -1.15780226157481, -0.319393727330983, 
-0.319393727330983, -0.319393727330983, -0.319393727330983, 0.519014806912847, 
0.519014806912847, 0.519014806912847, -0.738597994452898, -0.738597994452898, 
2.19583187540051, 2.19583187540051, -1.15780226157481, -0.319393727330983, 
-0.319393727330983, 0.519014806912847, 1.35742334115668, 0.519014806912847
), .Dim = c(21L, 1L), "`scaled:center`" = 3.76190476190476, "`scaled:scale`" = 2.38547190100328)), .Names = c("Demand", 
"normalized"), row.names = c(NA, -21L), class = "data.frame")
clusters <- kmeans(demand.sm[ , "normalized"], 5)

demand.dist <- dist(demand.sm[ , "normalized"]) 
demand.mds <- cmdscale(demand.dist) # multidimensional scaling of data matrix, aka principal coordinates analysis
c.chars <- c("*", "o", "+")[as.integer(clusters$Context)] 
a.cols <- rainbow(3)[clusters$cluster] 
plot(demand.mds, col=a.cols, pch=c.chars, xlab="X", ylab="Y")

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27407087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档