1
rd-8. クラスタリング
金子邦彦
データサイエンス演習
R システムを使用)
https://www.kkaneko.jp/de/rd/index.html
rd-8. クラスタリング
Rシステムでデータサイエンス演習)
2
金子邦彦
https://www.kkaneko.jp/cc/rd/index.html
クラスタリング
集団が2つ以上 (外れ値とは違う)
3
クラスタデータの合成の例
4
cは、ベクトルデータの連結
集団が2つ x<- rnorm(100000, mean=5, sd=5)
y<- rnorm(100000, mean=5, sd=5)
x2 <- rnorm(80000, mean=-15, sd=1)
y2 <- rnorm(80000, mean=-2, sd=1)
x3 <- c( x, x2 )
y3 <- c( y, y2 )
n <- floor( runif(100, 1, 180000+1) )
d12 <- data.frame( xx=x3[n], yy=y3[n] )
library(ggplot2)
ggplot(d12, aes(x=xx)) +
geom_point( aes(y=yy), size=3) + theme_bw()
mclust パッケージを使うには
準備
インターネット接続が必要
インストール
install.packages("mclust")
5
クラスタリングの例
6
library(mclust)
c <- Mclust(d12, modelNames="VVV")
print(c$classification)
クラスタリングの結果を,色付きの散布図
でプロット
7
library(mclust)
c <- Mclust(d12, modelNames="VVV")
print(c$classification)
library(ggplot2)
ggplot(d12, aes(x=xx)) +
geom_point( aes(y=yy), size=3, col=c$classification ) + theme_bw()