Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csetzkorn/478b49610526da85bd1424ef197c896d to your computer and use it in GitHub Desktop.
Save csetzkorn/478b49610526da85bd1424ef197c896d to your computer and use it in GitHub Desktop.
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