(1)凝集型階層
> library(cluster)
> cluster.agnes <- agnes="" mysql.data="" span="" stand="T)">> plot(cluster.agnes, which = 2, main = "", xlab = "", ylab = "")
(2) 区分型階層
> cluster.diana <- diana="" mysql.data="" span="" stand="T)">> plot(cluster.diana, which = 2, main = "", xlab = "", ylab = "")
(3) k-means法
> cluster.kmeans = kmeans(dist(mysql.data), 6) > cluster.kmeans$cluster 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 5 5 5 5 5 5 5 5 5 5 5 1 1 1 1 1 6 1 3 3 3 3 3 3 2 4 4 4 4 4 4 4 4 4 4 4 4 4 2 6
> cluster.kmeans$size [1] 6 2 6 13 11 2
> cluster.kmeans$withinss [1] 57677.519 5325.897 82998.094 383242.093 83159.601 102326.957
> clusplot(mysql.data, cluster.kmeans$cluster, color=TRUE, shade=TRUE, labels=2, lines=0)
(4) 階層クラスタリング
> rect.hclust(hclust(dist(mysql.data), method="ward.D"), k = 5, border = "red")
[Cluster.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
cluster.agnes <- function(name){ | |
cluster.agnes <- agnes(name, stand = T) | |
plot(cluster.agnes, which = 2, main = "", xlab = "", ylab = "") | |
} | |
cluster.diana <- function(name){ | |
cluster.diana <- agnes(name, stand = T) | |
plot(cluster.diana, which = 2, main = "", xlab = "", ylab = "") | |
} | |
cluster.kmeans <- function(name){ | |
cluster.kmeans = kmeans(dist(name), 6) | |
cluster.kmeans$cluster | |
cluster.kmeans$size | |
clusplot(name, cluster.kmeans$cluster, color=TRUE, shade=TRUE, labels=2, lines=0) | |
} | |
cluster.hclust <- function(name){ | |
rect.hclust(hclust(dist(name), method="ward.D"), k = 5, border = "red") | |
} |
参考
http://catcher-in-the-tech.net/2035/
http://d.hatena.ne.jp/maito610/20120810/p1
0 件のコメント:
コメントを投稿