实验报告材料聚类分析报告_第1页
实验报告材料聚类分析报告_第2页
实验报告材料聚类分析报告_第3页
已阅读5页,还剩30页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实验报告聚类分析实验原理:K均值聚类、中心点聚类、系统聚类和EM算法聚类分析技术。实验题目:用鸢尾花的数据集,进行聚类挖掘分析。实验要求:探索鸢尾花数据的基本特征,利用不同的聚类挖掘方法,获得基本结论并简明解释。实验题目-分析报告:data(iris)> rm(list=ls()> gc()used (Mb) gc trigger (Mb) max used (Mb)Ncells 431730 23.1929718 49.7 607591 32.5Vcells 787605 6.18388608 64.0 1592403 12.2> data(iris)> datav-

2、iris> head(data)Sepal.Length Sepal.Width Petal.Length Petal.Width Specie s15.13.51.40.2setosa24.93.01.40.2setosa34.73.21.30.2setosa44.63.11.50.2setosa55.03.61.40.2setosa65.43.91.70.4setosa#Kmean聚类分析> n ewiris <- iris> n ewiris$Species <- NULL> (kc <- kmea ns(n ewiris, 3)K-mea ns

3、 clusteri ng with 3 clusters of sizes 62, 50, 38Cluster mea ns:Sepal.Length Sepal.Width Petal.Length Petal.Width5.9016132.7483874.3935481.4338715.0060003.4280001.4620000.2460006.8500003.0736845.7421052.071053Clusteri ng vector:1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 241 2 2

4、 2 2 2 2 2 2 2 2 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 11 1 1 1 3 1 181 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 3 3 3 3 1 3 3 3 3 3 31 1 3 3 3 3 1121 3 1 3 1 3 3 1 1 3 3 3 3 3 1 3 3 3 3 1 3 3 3 1 3 3 3 1 3 3 1With in cluster sum of squares by cluster:1 39.82097 15.15100 23.87947(between_SS

5、 / total_SS = 88.4 %)Available comp onen ts:1 "cluster" "centers""totss""withinss""tot.withinss""betweenss" "size""iter""ifault"> table(iris$Species, kc$cluster)1 2 3setosa 0 50 0versicolor 48 0 2virgi nica

6、14 0 36> plot( newirisc("Sepal.Le ngth", "Sepal.Width"), col = kc $cluster)> poi nts(kc$ce nters,c("Sepal.Le ngth", "Sepal.Width"), c ol = 1:3, pch = 8, cex=2)455055 flO Q5 7075 8DSep« I Lengthgm 0打#K-Mediods 进行聚类分析> in stall.packages("clust

7、er")> library(cluster)> iris.pam<-pam(iris,3)> table(iris$Species,iris.pam$clusteri ng)setosa 50 0 0versicolor 0 3 47virgi nica 0 49 1> layout(matrix(c(1,2),1,2)> plot(iris.pam)clusplot(pam(x = iris, k = 3|)Silh ouette plot of pam(x = iris, k = 3) n-1503 AJStefSJ. avei,ci 3CJ

8、-3210123CNC94JCIU.E1JO1. 50 | 0.002 52 | 0.413 48 | 051Coinpunenl 1These two comporteins explain $5 02po rit«o.o 020.4 D.a o.e i.oSilboued:e widtsti 哥Arage sinowHie widlti - 0.57> layout(matrix(1)#hc> iris.hc <- hclust( dist(iris,1:4)> plot( iris.hc, hang = -1)> plclust( iris.hc,

9、 labels = FALSE, ha ng = -1)> re <- rect.hclust(iris.hc, k = 3)> iris.id <- cutree(iris.hc, 3)dist(iris, 1:4hclust (: "complete")#利用剪枝函数cutree() 参数h控制输出height=18 时的系谱类别> sapply (uniq ue(iris.id),+function( g)iris$Speciesiris.id=g)11 setosa setosa setosa setosa setosa setosa

10、setosa setosa setosa setosa setosa12 setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa23 setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa34 setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa45 setosa setosa setosa setos

11、a setosa setosaLevels: setosa versicolor virginica2 1 versicolor versicolor versicolor versicolor versicolor versicolor versicolor 8 versicolor versicolor versicolor versicolor versicolor versicolor versicolor15 versicolor versicolor versicolor versicolor versicolor versicolor versicolor22 versicolo

12、r versicolor virginica virginica virginica virginica virginica29 virginicavirginicavirginicavirginicavirginicavirginicavirginica36 virginicavirginicavirginicavirginicavirginicavirginicavirginica43 virginicavirginicavirginicavirginicavirginicavirginicavirginica50 virginicavirginicavirginicavirginicav

13、irginicavirginicavirginica57 virginicavirginicavirginicavirginicavirginicavirginicavirginica 64 virginica virginica virginica virginica virginica virginica virginica71 virginica virginicaLevels: setosa versicolor virginica3 1 versicolor versicolor versicolor versicolor versicolor versicolor versicol

14、or 8 versicolor versicolor versicolor versicolor versicolor versicolor versicolor 15 versicolor versicolor versicolor versicolor versicolor versicolor versicolor22 versicolor versicolor versicolor versicolor versicolor versicolor virginicaLevels: setosa versicolor virginica> plot(iris.hc)> rec

15、t.hclust(irisborder="light grey")#用浅灰色矩形用浅灰色矩形框> rect.hclust(iris.hc,k=3,border="dark grey")#出3分类聚类结果> rect.hclust(iris.hc,k=7,which=c(2,6),border="dark grey ")Cluiter DendragiTAmesiii 啦 1# DBSCAN #基于密度的聚类> in stall.packages("fpc")> library(fpc)>

16、; ds仁dbscan(iris,1:4,eps=1,MinPts=5)#半径参数为 1,密度阈值为5> ds1dbsca n Pts=150 Mi nPts=5 eps=11 2border 0 1seed 50 99total 50 100> ds2=dbsca n(iris,1:4,eps=4,Mi nPts=5)> ds3=dbsca n(iris,1:4,eps=4,Mi nPts=2)> ds4=dbsca n(iris,1:4,eps=8,Mi nPts=2)> par(mfcol=c(2,2)> plot(ds1,iris,1:4,main=

17、"1: MinPts=5 eps=1")> plot(ds3,iris,1:4,main="3: MinPts=2 eps=4")> plot(ds2,iris,1:4,main="2: MinPts=5 eps=4")> plot(ds4,iris,1:4,main="4: MinPts=2 eps=8")Sepal.Length4: MinPts=2 eps=82.Q3.G"0.5152 5Pet日 LL engthPetal Width.AIIIIIIrniiiiir4.5S.56

18、.57.512 3 4 5 6 7> d=dist(iris,1:4)#计算数据集的距离矩阵d> max(d);mi n(d)#计算数据集样本的距离的最值1 7.0851961 0> in stall.packages("ggplot2")> library(ggplot2)> in terval=cut_i nterval(d,30)> table(i nterval)interval0,0.236 (0.236,0.472 (0.472,0.709 (0.709,0.945 (0.945,1.18 (1.18,1.4288585876

19、891831688(1.42,1.65(1.65,1.89(1.89,2.13(2.13,2.36(2.36,2.6(2.6,2.83543369379339335406(2.83,3.07(3.07,3.31(3.31,3.54(3.54,3.78 (3.78,4.01 (4.01,4.25458(4.25,4.49349(5.67,5.997459465480468505(4.49,4.72 (4.72,4.96(4.96,5.2(5.2,5.43 (5.43,5.67385321291187(5.9,6.14 (6.14,6.38 (6.38,6.61 (6.61,6.85 (6.85,

20、7.09927850184> which.max(table(i nterval) (0.709,0.9454> for(i in 3:5)+ for(j in 1:10)+ ds=dbsca n(iris,1:4,eps=i,M in Pts=j)+prin t(ds)+ + dbscan Pts=150 Min Pts=1 eps=31seed 150total 150dbscan Pts=150 Min Pts=2 eps=31seed 150total 150dbscan Pts=150 Min Pts=3 eps=31seed 150 dbscan Pts=150 Mi

21、nPts=4 eps=3seed 150total 150dbscan Pts=150 MinPts=5 eps=31seed 150total 150dbscan Pts=150 Min Pts=6 eps=31seed 150total 150dbscan Pts=150 Min Pts=7 eps=31seed 150total 150dbscan Pts=150 Min Pts=8 eps=31seed 150total 150dbscan Pts=150 Min Pts=9 eps=31seed 150total 150dbscan Pts=150 Mi nPts=10 eps=31

22、seed 150dbscan Pts=150 MinPts=1 eps=41seed 150total 150dbscan Pts=150 Mi nPts=2 eps=41seed 150total 150dbscan Pts=150 Mi nPts=3 eps=41seed 150total 150dbsca n Pts=150 Mi nPts=4 eps=41seed 150total 150dbsca n Pts=150 Mi nPts=5 eps=41seed 150total 150dbscan Pts=150 Mi nPts=6 eps=41seed 150total 150dbs

23、ca n Pts=150 Min Pts=7 eps=41seed 150total 150dbscan Pts=150 MinPts=8 eps=41seed 150total 150dbscan Pts=150 Min Pts=9 eps=41seed 150total 150dbscan Pts=150 Mi nPts=10 eps=41seed 150total 150dbscan Pts=150 MinPts=1 eps=51seed 150total 150dbscan Pts=150 Min Pts=2 eps=51seed 150total 150dbscan Pts=150

24、Min Pts=3 eps=51seed 150total 150dbscan Pts=150 MinPts=4 eps=51seed 150total 150dbscan Pts=150 MinPts=5 eps=51seed 150total 150dbscan Pts=150 Min Pts=6 eps=51seed 150total 150dbscan Pts=150 MinPts=7 eps=51seed 150total 150dbscan Pts=150 Min Pts=8 eps=51seed 150total 150dbscan Pts=150 Min Pts=9 eps=5

25、1seed 150total 150dbscan Pts=150 Mi nPts=10 eps=51seed 150total 150#30次dbscan的聚类结果> ds5=dbsca n(iris,1:4,eps=3,Mi nPts=2)> ds6=dbsca n(iris,1:4,eps=4,Mi nPts=5)> ds7=dbsca n(iris,1:4,eps=5,Mi nPts=9)> par(mfcol=c(1,3)> plot(ds5,iris,1:4,main="1: MinPts=2 eps=3")> plot(ds6

26、,iris,1:4,mai n="3: Min Pts=5 eps=4")> plot(ds7,iris,1:4,main="2: MinPts=9 eps=5")2: MinPts=9 eps=52.03.0*.0Sepal LengthSepaLWidthPetal. Length4.5S.56.57.5Petal.Width12 3 4 5 6 7# EM期望最大化聚类> in stall.packages("mclust")> library(mclust)> fit_EM=Mclust(iris,1:

27、4)fitting .> summary(fit_EM)Mclust VEV (ellipsoidal, equal shape) model with 2 comp onents: log.likelihood n df BIC ICL-215.726 150 26 -561.7285 -561.7289Clusteri ng table:1 250 100> summary(fit_EM,parameters=TRUE)Gaussian finite mixture model fitted by EM algorithmMclust VEV (ellipsoidal, equ

28、al shape) model with 2 comp one nts:log.likelihood n df BIC ICL-215.726 150 26 -561.7285 -561.7289Clusteri ng table:1 250 100Mixing probabilities:1 20.3333319 0.6666681Means:,1 ,2Sepal.Le ngth 5.0060022 6.261996Sepal.Width 3.4280049 2.871999Petal.Le ngth 1.4620007 4.905992Petal.Width 0.2459998 1.675

29、997Varia nces:,1Sepal.Length Sepal.Width Petal.Length Petal.WidthSepal.Length 0.15065114 0.13080115 0.02084463 0.01309107Sepal.Width 0.13080115 0.17604529 0.01603245 0.01221458Petal.Le ngth 0.02084463 0.01603245 0.02808260 0.00601568Petal.Width 0.01309107 0.01221458 0.00601568 0.01042365 ,2Sepal.Len

30、gth Sepal.Width Petal.Length Petal.WidthSepal.Le ngth 0.4000438 0.10865444 0.3994018 0.14368256Sepal.Width0.1086544 0.10928077 0.1238904 0.07284384Petal.Le ngth 0.3994018 0.12389040 0.6109024 0.25738990Petal.Width0.1436826 0.07284384 0.2573899 0.16808182> plot(fit_EM)# 对EM聚类结果作图Model-based cluste

31、ri ng plots:1: BIC2: classificati on3: un certa inty4: den sitySelectio n:(下面显示选项)#选1$巳卩 al.LengthSepal. Width15 1.Q 1.S 2 0 2.5Petal WidthS巳卩 al.LengthV P I*-尹尹iSep al. Width二澎、< J . BB: 叩鬲JPeted 丄 ength* ' H”H4*:-1 r -kk I ',歹Illi 111 q4 55.5657.511厂 111112 3 4 5 6 715 1.Q 1.S 2 0 2.5-n

32、-CMPetal WidthSelectio n: 0> iris_BIC=mclustBIC(iris,1:4)fitting .|=|100%> iris_BICsum=summary(iris_BIC,data=iris,1:4)> iris_BICsum # 获取数1据集iris在各模型和类别数下的BIC值Best BIC values:VEV,2 VEV,3 VVV,2BIC -561.7285 -562.5522369 -574.01783BIC diff 0.0000 -0.8237748 -12.28937Classification table for mo

33、del (VEV,2):50 100> iris_BICBayesian Information Criterion (BIC):EII VII EEI VEI EVI VVI EEE1 -1804.0854 -1804.0854 -1522.1202 -1522.1202 -1522.1202 -1522.1202 -829.97822 -1123.4117 -1012.2352 -1042.9679 -956.2823 -1007.3082 -857.5515 -688.09723 -878.7650 -853.8144 -813.0504 -779.1566 -797.8342 -

34、744.6382 -632.96474 -893.6140 -812.6048 -827.4036 -748.4529 -837.5452 -751.0198 -646.02585 -782.6441 -742.6083 -741.9185 -688.3463 -766.8158 -711.4502 -604.81316 -715.7136 -705.7811 -693.7908 -676.1697 -774.0673 -707.2901 -609.85437 -731.8821 -698.5413 -713.1823 -680.7377 -813.5220 -766.6500 -632.49

35、478 -725.0805 -701.4806 -691.4133 -679.4640 -740.4068 -764.1969 -639.26409 -694.5205 -700.0276 -696.2607 -702.0143 -767.8044 -755.8290 -653.0878EVE VEE VVE EEV VEV EVV VVV1 -829.9782 -829.9782 -829.9782 -829.9782 -829.9782 -829.9782 -829.97822 -657.2263 -656.3270 -605.1841 -644.5997 -561.7285 -658.3

36、306 -574.01783 -666.5491 -605.3982 -636.4259 -644.7810 -562.5522 -656.0359 -580.83964 -705.5435 -604.8371 -639.7078 -699.8684 -602.0104 -725.2925 -630.6006 -661.9497 -609.5584 -664.8224 -664.4537 -679.5116 NA -754.79387 -699.5102 NA -690.6108 -709.9530 -704.7699 -809.8276 -806.92778 -700.4277 -654.8237 -709.9392 -735.4463 -712.8788 -831.7520 -830.63739 -729.6651 NA -734.2997 -758.9348 -748.8237 -882.4391 -883.6931 Top 3 models based on the BIC criterion:VEV,2 VEV,3 VVV,2-561.7285 -562.5522 -574.0178> par(mfcol=c(1,1)> plot(iris_BIC,G=1:7,col="yellow"

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论