如何在Google地图上可视化SOM群集?

时间:2019-05-01 08:16:02

标签: r

我的主管要求我使用SOM可视化Google地图上的聚类。但是我在这个方向上找不到任何有用的参考。有人可以帮我吗?

我有地震数据集,具有四个特征(经度,纬度,震级和深度)。

我已经使用四个功能完成了聚类。


earthquake<-read.csv(choose.files(),header = T)
head(earthquake)

train<-earthquake[,c(5,6,7,8)]
scaled<-as.matrix(scale(train))
som_grid<-somgrid(xdim = 14,ydim=14,topo = "hexagonal")


som_model<-som(scaled, grid=som_grid, rlen=6000, 
alpha=c(0.05,0.01))

#Trainig progress
plot(som_model,type="changes")
#synopses (connections) 

#Node counts
plot(som_model,type = "count")

#Neighbour Distance
plot(som_model,type = "dist.neighbours")

Code/Weight vectors

plot(som_model,type = "codes")

Heatmaps

coolBlueHotRed <- function(n, alpha = 1) {rainbow(n, end=4/6, alpha=alpha)[n:1]}
mydata<-as.data.frame(som_model$codes)
plot(som_model, type = "property", property=mydata[,4],main=names(mydata)[4],palette.name = coolBlueHotRed)
plot(som_model, type = "property", property=mydata[,3],main=names(mydata)[3],palette.name = coolBlueHotRed)


coolBlueHotRed <- function(n, alpha = 1) {rainbow(n, end=4/6, alpha=alpha)[n:1]}
var_unscaled <- aggregate(as.numeric(train[,var]), by=list(as.data.frame(som_model$unit.classif)), FUN=mean, simplify=TRUE)[,2]
plot(som_model, type = "property", property=var_unscaled, main=names(data_train)[var], palette.name=coolBlueHotRed)

mydata <- as.data.frame(som_model$codes) 
wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var)) 
for (i in 2:20) {
  wss[i] <- sum(kmeans(mydata, centers=i)$withinss)
}

grid(plot(wss,type="b"),5,lwd = 3,equilogs = T)
## use hierarchical clustering to cluster the codebook vectors
som_cluster <- cutree(hclust(dist(mydata)), 6)
# plot these results:

clustering 
pretty_palette <- c("#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')
plot(som_model, type="codes", main = "Clusters",bgcol=pretty_palette[som_cluster]) 
add.cluster.boundaries(som_model, som_cluster)

0 个答案:

没有答案