Created
February 18, 2015 09:05
-
-
Save shirayuca/467a5360751b686766a3 to your computer and use it in GitHub Desktop.
ykmeans.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
アイテム名 | y | x1 | x2 | x3 | |
---|---|---|---|---|---|
【アサヒ飲料】十六茶 | 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
library(ykmeans) | |
data <- read.csv("data.csv", sep=",", header=T, row.names=1) | |
data.sc <- scale(data) #データを標準化(各変量の単位が異なる場合) | |
data.df <- as.data.frame(data.sc) | |
ykm <- ykmeans(data.df, paste0("x", 1:10), "y", 7:15, n=500) #引数は、データフレーム、説明変数、比較する変数、クラスタ数候補、k-means試行回数 | |
table(ykm$cluster) | |
write.table(ykm$cluster, sep=",", "ykm.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment