#############################
#####Self-organizing maps####
#############################
# Unsupervised self-Organizing Maps
#install.packages("kohonen")
library(kohonen)
# file setting
setwd("C:/Users/qkz952/Desktop/Published outputs/Courses/SOM_GWR")
library(readxl)
#watershed scale input data
data<-read.csv("SOMdata.csv",header=T)
#data pre-processing
str(data)
X<-scale(data[,-1])
summary(X)
# SOM
set.seed(2022)
g<-somgrid(xdim=3,ydim=2,topo="rectangular")
map<-som(X,grid=g,radius=1)
# map results
plot(map, type="counts")
plot(map, type="codes")
#output results
map$codes
map$unit.classif
output<-cbind(data,map$unit.classif)
write.table(output,file="BundleResultsSOM.csv",sep = ",",row.names=FALSE)
生态系统服务功能簇划分 SOM代码(个人学习笔记备份)
于 2024-06-16 21:17:07 首次发布