问题描述
我在 R 中做 SOM 并且我做了 SOM 代码的聚类。我面临的问题是我需要从左上到下计数的 SOM 映射节点。但是在我的情况下,它从左下角开始,并且聚类树状图也与映射图相同?我该如何解决这个问题?给定的 SOM 映射图形节点和树状图不匹配。为什么节点数从底部开始?我需要它从左上角开始。
我使用的代码是
library(som)
env.active1 <- env_table1[,2:19]
#scale data
iris.sc = scale(env_table1[,2:19])
head(iris.sc)
summary(iris.sc)
library(kohonen)
#Choosing Grid
#iris.grid <- somgrid(xdim = 5,ydim=6,topo="hexagonal")
#Build model
iris.som <- supersom(iris.sc,grid=iris.grid,rlen=1000,alpha=c(0.05,0.01),keep.data = TRUE)
summary(iris.som)
meanD <- mean(iris.som$distances)
# Weight Vector View
plot(iris.som,type="codes")
plot(iris.som,type="mapping",border = "grey",shape = "straight")#The lower number of empty cells,the better SOM.
plot(iris.som,type="quality",shape = "straight")
###
## Show the U matrix
Umat <- plot(iris.som,type="dist.neighbours",main = "SOM neighbour distances")
set.seed(123)
par(mfrow = c(1,1))
#cluster - WITH WARDS METHOD
df <- dist(iris.som$codes[[1]])
dd <- dist(df,method = "euclidean")
cah <- hclust(dd,method="ward.D2")
plot(cah,cex = 0.6,hang = -1)
#visualizing the clusters into the dendrogram
plot(cah,cex = 0.6)
rect.hclust(cah,k = 4,border = 2:5)
groupes4 <- cutree(cah,k=4)
[enter image description here][1]
#highlight the clusters into the Kohonen map
plot(iris.som,bgcol=c("#01B4C6","#FEDF25","#00AF66FF","#F675DA")[groupes4],labels = env_table1$season)
我
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)