當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R xclara 具有 3 個聚類的雙變量數據集

R語言 xclara 位於 cluster 包(package)。

說明

一個人工數據集,由 3 個 well-separated 簇中的 3000 個點組成。

用法

data(xclara)

格式

一個 DataFrame ,對 2 個數值變量(名為 V1V2 )進行 3000 個觀測,分別給出點的 坐標。

注意

我們的 xclara 版本比 read.table("xclara.dat") 版本稍微更圓潤,all.equal 測量的相對差異是 1.15e-7(對於 V1)和 1.17e-7(對於 V2),這表明我們的版本已options(digits = 7) 格式化的結果。

此前(2017 年 5 月之前),據稱這三個簇的大小均為 1000,這顯然是錯誤的。 pam(*, 3) 給出的簇大小為 899、1149 和 952,除了七個 “outliers” (或 “mislabellings”)對應於觀察索引 ,請參見示例。

例子

## Visualization: Assuming groups are defined as {1:1000}, {1001:2000}, {2001:3000}
plot(xclara, cex = 3/4, col = rep(1:3, each=1000))
p.ID <- c(78, 1411, 2535) ## PAM's medoid indices  == pam(xclara, 3)$id.med
text(xclara[p.ID,], labels = 1:3, cex=2, col=1:3)

 px <- pam(xclara, 3) ## takes ~2 seconds
 cxcl <- px$clustering ; iCl <- split(seq_along(cxcl), cxcl)
 boxplot(iCl, range = 0.7, horizontal=TRUE,
         main = "Indices of the 3 clusters of  pam(xclara, 3)")

 ## Look more closely now:
 bxCl <- boxplot(iCl, range = 0.7, plot=FALSE)
 ## We see 3 + 2 + 2 = 7  clear "outlier"s  or "wrong group" observations:
 with(bxCl, rbind(out, group))
 ## out   1038 1451 1610   30  327  562  770
 ## group    1    1    1    2    2    3    3
 ## Apart from these, what are the robust ranges of indices? -- Robust range:
 t(iR <- bxCl$stats[c(1,5),])
 ##    1  900
 ##  901 2050
 ## 2051 3000
 gc <- adjustcolor("gray20",1/2)
 abline(v = iR, col = gc, lty=3)
 axis(3, at = c(0, iR[2,]), padj = 1.2, col=gc, col.axis=gc)

來源

示例數據集附有以下參考文獻(文件‘xclara.dat' 裏麵 'clus_examples.tar.gz’)。

參考

Anja Struyf, Mia Hubert & Peter J. Rousseeuw (1996) Clustering in an Object-Oriented Environment. Journal of Statistical Software 1. doi:10.18637/jss.v001.i04

相關用法


注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Bivariate Data Set with 3 Clusters。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。