Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fit Self-Organizing Map Plus Predefined Boundaries
library(dplyr)
library(kohonen)
setwd('C:\\Users\\Christian\\Source\\Repos\\BlaDiBla')
OrginalData <- read.table("IrisData.txt",
header = TRUE, sep = "\t")
SubsetData <- subset(OrginalData, select = c("SepalLength", "SepalWidth", "PetalLength", "PetalWidth"))
TrainingMatrix <- as.matrix(scale(SubsetData))
GridDefinition <- somgrid(xdim = 4, ydim = 4, topo = "hexagonal")
SomModel <- kohonen::supersom(data = TrainingMatrix, grid = GridDefinition, rlen = 1000, alpha = c(0.05, 0.01),
keep.data = TRUE)
groups = 3
iris.hc = cutree(hclust(dist(SomModel$codes[[1]])), groups)
plot(SomModel, type = "codes", bgcol = rainbow(groups)[iris.hc])
add.cluster.boundaries(SomModel, iris.hc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.