Last active
August 29, 2015 14:15
-
-
Save shirayuca/a01e500d1aaa60b74647 to your computer and use it in GitHub Desktop.
kohonen_repeat.R
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
アイテム名 | 2392 | 2461 | 2739 | 3178 | |
---|---|---|---|---|---|
【アサヒ飲料】十六茶 | 0 | 0 | 0 | 0 | |
【伊藤園】お~いお茶 濃い味 | 0 | 0 | 0 | 0 | |
【伊藤園】お~いお茶 緑茶 | 0 | 0 | 0 | 0 | |
【キリン】生茶 | 0 | 0 | 0 | 0 | |
【コカ・コーラ】綾鷹 | 0 | 0 | 0 | 1 | |
【コカ・コーラ】爽健美茶 | 0 | 0 | 1 | 0 | |
【サントリー】伊右衛門 | 0 | 0 | 0 | 1 | |
【大塚製薬】ポカリスエット | 0 | 0 | 0 | 0 | |
【コカ・コーラ】コカ・コーラ | 1 | 1 | 0 | 0 |
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
### Rで自己組織化マップを複数回実施 | |
### 設定 | |
library("kohonen") | |
data <- read.csv("data.csv", sep=",", header=T, row.names=1) #データの読み込み | |
data.sc <- scale(data) | |
data.scc <- ifelse(is.na(data.sc), 0, data.sc) | |
### 0回目 | |
set.seed(0) #n回目に変更 | |
SOM0 <- som(data.scc, grid=somgrid(19,19, "rectangular")) #n回目に変更 #アイテム数によってx,yを変更。x*y<=アイテム数。 | |
XY1 <- SOM0$grid$pts #n回目に変更 | |
xy1 <- matrix(numeric(2*nrow(data)), ncol=2) | |
for(i in 1:nrow(data)){ | |
xy1[i,]<-XY1[SOM0$unit.classif[i], 1:2] #n回目に変更 | |
} | |
SOM0.t <- cbind(rownames(data.scc), xy1) #n回目に変更 | |
options(encoding="UTF-8") | |
write.table(SOM0.t, "SOM0.csv") #n回目に変 | |
### 1回目 | |
set.seed(1) #n回目に変更 | |
SOM1 <- som(data.scc, grid=somgrid(19,19, "rectangular")) #n回目に変更 #アイテム数によってx,yを変更。x*y<=アイテム数。 | |
XY1 <- SOM1$grid$pts #n回目に変更 | |
xy1 <- matrix(numeric(2*nrow(data)), ncol=2) | |
for(i in 1:nrow(data)){ | |
xy1[i,]<-XY1[SOM1$unit.classif[i], 1:2] #n回目に変更 | |
} | |
SOM1.t <- cbind(rownames(data.scc), xy1) #n回目に変更 | |
options(encoding="UTF-8") | |
write.table(SOM1.t, "SOM1.csv") #n回目に変 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment