Created
May 15, 2017 20:16
-
-
Save csetzkorn/478b49610526da85bd1424ef197c896d to your computer and use it in GitHub Desktop.
Fit Self-Organizing Map Plus Predefined Boundaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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