SORU
13 Mart 2013, ÇARŞAMBA


Ar-küme analizi: kümeler uygun sayısını belirlemek

R Merhaba, k-ortalamalar analizi kümeleri en iyi seçmek için nasıl çok emin değilim. Veri altında bir alt çizme sonra, kaç kümeler uygun olur? Nasıl küme dendro analiz yapabilir miyim?

n = 1000
kk = 10    
x1 = runif(kk)
y1 = runif(kk)
z1 = runif(kk)    
x4 = sample(x1,length(x1))
y4 = sample(y1,length(y1)) 
randObs <- function()
{
  ix = sample( 1:length(x4), 1 )
  iy = sample( 1:length(y4), 1 )
  rx = rnorm( 1, x4[ix], runif(1)/8 )
  ry = rnorm( 1, y4[ix], runif(1)/8 )
  return( c(rx,ry) )
}  
x = c()
y = c()
for ( k in 1:n )
{
  rPair  =  randObs()
  x  =  c( x, rPair[1] )
  y  =  c( y, rPair[2] )
}
z <- rnorm(n)
d <- data.frame( x, y, z )

CEVAP
13 Mart 2013, ÇARŞAMBA


Eğer Sorunuzun how can I determine how many clusters are appropriate for a kmeans analysis of my data?, daha sonra ise burada bazı seçenekler var. Kümelerin belirlenmesi numaraları wikipedia article bu yöntemlerden bazıları çok iyi yorumlar var.

İlk olarak, bazı tekrarlanabilir verileri (Q verileri... bana açık değildir):

n = 100
g = 6 
set.seed(g)
d <- data.frame(x = unlist(lapply(1:g, function(i) rnorm(n/g, runif(1)*i^2))), 
                y = unlist(lapply(1:g, function(i) rnorm(n/g, runif(1)*i^2))))
plot(d)

enter image description here

Bir. Bend veya hata Kare toplamı dirsek (SSE) eteğindeki bir arsa arayın. http://www.statmethods.net/advstats/cluster.html & http://www.mattpeeples.net/kmeans.html daha fazlası için bkz. Elde edilen arsa dirsek yeri kmeans kümeler için uygun bir rakam öneriyor:

mydata <- d
wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var))
  for (i in 2:15) wss[i] <- sum(kmeans(mydata,
                                       centers=i)$withinss)
plot(1:15, wss, type="b", xlab="Number of Clusters",
     ylab="Within groups sum of squares")

4 kümeler bu yöntem tarafından belirtilen olacağını söyleyebiliriz: enter image description here

İki. Medoids etrafında bölümleme kümeleri fpc paketinde pamk işlevini kullanarak sayısını tahmin etmek için yapabilirsiniz.

library(fpc)
pamk.best <- pamk(d)
cat("number of clusters estimated by optimum average silhouette width:", pamk.best$nc, "\n")
plot(pam(d, pamk.best$nc))

enter image description here enter image description here

# we could also do:
library(fpc)
asw <- numeric(20)
for (k in 2:20)
  asw[[k]] <- pam(d, k) $ silinfo $ avg.width
k.best <- which.max(asw)
cat("silhouette-optimal number of clusters:", k.best, "\n")
# still 4

Üç. Calinsky kriteri: kaç kümeler uygun teşhis için Başka bir yaklaşım verileri. Bu durumda 1'den 10'a gruplar çalışıyoruz.

require(vegan)
fit <- cascadeKM(scale(d, center = TRUE,  scale = TRUE), 1, 10, iter = 1000)
plot(fit, sortg = TRUE, grpmts.plot = TRUE)
calinski.best <- as.numeric(which.max(fit$results[2,]))
cat("Calinski criterion optimal number of clusters:", calinski.best, "\n")
# 5 clusters!

enter image description here

Dört. Beklenti-firma için Bayesian Bilgi Kriteri göre kümeler, parametreli Gauss karışım modelleri için hiyerarşik kümeleme tarafından başlatılan en uygun model ve sayısını belirlemek

# See http://www.jstatsoft.org/v18/i06/paper
# http://www.stat.washington.edu/research/reports/2006/tr504.pdf
#
library(mclust)
# Run the function to see how many clusters
# it finds to be optimal, set it to search for
# at least 1 model and up 20.
d_clust <- Mclust(as.matrix(d), G=1:20)
m.best <- dim(d_clust$z)[2]
cat("model-based optimal number of clusters:", m.best, "\n")
# 4 clusters
plot(d_clust)

enter image description here enter image description here enter image description here

Beş. Affinity yayılma (AP) kümeleme, http://dx.doi.org/10.1126/science.1136800 bkz

library(apcluster)
d.apclus <- apcluster(negDistMat(r=2), d)
cat("affinity propogation optimal number of clusters:", length(d.apclus@clusters), "\n")
# 4
heatmap(d.apclus)
plot(d.apclus, d)

enter image description here enter image description here

Altı. Küme Sayısını Tahmin etmek için boşluk İstatistik. Ayrıca Bkz: 34**. Burada 2 ile 10 arası kümeleri çalışıyor:

library(cluster)
clusGap(d, kmeans, 10, B = 100, verbose = interactive())

Clustering k = 1,2,..., K.max (= 10): .. done
Bootstrapping, b = 1,2,..., B (= 100)  [one "." per sample]:
.................................................. 50 
.................................................. 100 
Clustering Gap statistic ["clusGap"].
B=100 simulated reference sets, k = 1..10
 --> Number of clusters (method 'firstSEmax', SE.factor=1): 4
          logW   E.logW        gap     SE.sim
 [1,] 5.991701 5.970454 -0.0212471 0.04388506
 [2,] 5.152666 5.367256  0.2145907 0.04057451
 [3,] 4.557779 5.069601  0.5118225 0.03215540
 [4,] 3.928959 4.880453  0.9514943 0.04630399
 [5,] 3.789319 4.766903  0.9775842 0.04826191
 [6,] 3.747539 4.670100  0.9225607 0.03898850
 [7,] 3.582373 4.590136  1.0077628 0.04892236
 [8,] 3.528791 4.509247  0.9804556 0.04701930
 [9,] 3.442481 4.433200  0.9907197 0.04935647
[10,] 3.445291 4.369232  0.9239414 0.05055486

İşte gap Edwin Chen uygulanması istatistik çıktısı: enter image description here

Yedi. Ayrıca yararlı küme atama görselleştirmek, daha fazla ayrıntı için http://www.r-statistics.com/2010/06/clustergram-visualization-and-diagnostics-for-cluster-analysis-r-code/ görmek clustergrams ile veri keşfetmek için bulabilirsiniz.

Sekiz. NbClust package bir veri kümesi küme sayısını belirlemek için 30 endeksleri sağlar.

library(NbClust)
nb <- NbClust(d, diss="NULL", distance = "euclidean", 
        min.nc=2, max.nc=15, method = "kmeans", 
        index = "alllong", alphaBeale = 0.1)
hist(nb$Best.nc[1,], breaks = max(na.omit(nb$Best.nc[1,])))
# Looks like 3 is the most frequently determined number of clusters
# and curiously, four clusters is not in the output at all!

enter image description here

Eğer Sorunuzun how can I produce a dendrogram to visualize the results of my cluster analysis, daha sonra ise bu başlamalısın: http://www.statmethods.net/advstats/cluster.html http://www.r-tutor.com/gpu-computing/clustering/hierarchical-cluster-analysis http://gastonsanchez.wordpress.com/2012/10/03/7-ways-to-plot-dendrograms-in-r/ Ve bakın burada daha ilginç bir yöntem için: http://cran.r-project.org/web/views/Cluster.html

İşte birkaç örnek:

d_dist <- dist(as.matrix(d))   # find distance matrix 
plot(hclust(d_dist))           # apply hirarchical clustering and plot

enter image description here

# a Bayesian clustering method, good for high-dimension data, more details:
# http://vahid.probstat.ca/paper/2012-bclust.pdf
install.packages("bclust")
library(bclust)
x <- as.matrix(d)
d.bclus <- bclust(x, transformed.par = c(0, -50, log(16), 0, 0, 0))
viplot(imp(d.bclus)$var); plot(d.bclus); ditplot(d.bclus)
dptplot(d.bclus, scale = 20, horizbar.plot = TRUE,varimp = imp(d.bclus)$var, horizbar.distance = 0, dendrogram.lwd = 2)
# I just include the dendrogram here

enter image description here

Ayrıca yüksek boyutlu veri ölçekli bootstrap yeniden örnekleme) hiyerarşik kümeleme için p-değeri hesaplar pvclust kütüphane. İşte belgelerden örnek (benim örnekte olduğu gibi düşük boyutlu veri üzerinde alışkanlık iş):

library(pvclust)
library(MASS)
data(Boston)
boston.pv <- pvclust(Boston)
plot(boston.pv)

enter image description here

Bu yardımcı oldu mu?

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Disney Pets and Animals

    Disney Pets

    29 ŞUBAT 2012
  • Neil Cicierega

    Neil Ciciere

    22 Mart 2006
  • Phandroid

    Phandroid

    26 Ocak 2009