实验报告聚类分析

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验报告聚类分析

实验原理:K均值聚类、中心点聚类、系统聚类和EM算法聚类分析技术。

实验题目:用鸢尾花的数据集,进行聚类挖掘分析。

实验要求:探索鸢尾花数据的基本特征,利用不同的聚类挖掘方法,获得基本结论并简明解释。

实验题目--分析报告:data(iris)

> rm(list=ls())

> gc()

used (Mb) gc trigger (Mb) max used (Mb)

Ncells 431730 929718 607591

Vcells 787605 8388608 1592403

> data(iris)

> data<-iris

> head(data)

Species

1 setosa

2 setosa

3 setosa

4 setosa

5 setosa

6 setosa

#Kmean聚类分析

> newiris <- iris

> newiris$Species <- NULL

> (kc <- kmeans(newiris, 3))

K-means clustering with 3 clusters of sizes 62, 50, 38

Cluster means:

1

2

3

Clustering 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 2 2 2

2 2 2 2 2

[41] 2 2 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 1 1 1 1 1 3 1 1

[81] 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 3 1 1 3 3 3 3 1

[121] 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 1

Within cluster sum of squares by cluster:

[1]

(between_SS / total_SS = %)

Available components:

[1] "cluster" "centers" "totss" "withinss" ""

[6] "betweenss" "size" "iter" "ifault"

> table(iris$Species, kc$cluster)

1 2 3

setosa 0 50 0

versicolor 48 0 2

virginica 14 0 36

> plot(newiris[c("", "")], col = kc$cluster)

> points(kc$centers[,c("", "")], col = 1:3, pch = 8, cex=2)

#K-Mediods 进行聚类分析

> ("cluster")

> library(cluster)

> <-pam(iris,3)

> table(iris$Species,$clustering)

1 2 3

setosa 50 0 0

versicolor 0 3 47

virginica 0 49 1

> layout(matrix(c(1,2),1,2)) > plot

> layout(matrix(1))

#hc

> <- hclust( dist(iris[,1:4]))

> plot( , hang = -1)

> plclust( , labels = FALSE, hang = -1)

> re <- , k = 3)

> <- cutree, 3)

#利用剪枝函数cutree()参数h控制输出height=18时的系谱类别> sapply(unique,

+ function(g)iris$Species[==g])

[[1]]

[1] setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa

[12] setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa

[23] setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa

[34] setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa setosa

[45] setosa setosa setosa setosa setosa setosa

Levels: setosa versicolor virginica

[[2]]

[1] versicolor versicolor versicolor versicolor versicolor versicolor versicolor

[8] versicolor versicolor versicolor versicolor versicolor versicolor versicolor

[15] versicolor versicolor versicolor versicolor versicolor versicolor versicolor

[22] versicolor versicolor virginica virginica virginica virginica virginica

[29] virginica virginica virginica virginica virginica virginica virginica

相关文档
最新文档