- 2
- 0
- 约1.58千字
- 约 3页
- 2021-02-25 发布于天津
- 举报
R 语言学习笔记 -K 平均算法(聚类)
k-means Clustering
This page demonstrates k-means clustering with R.
newiris - iris
newiris$Species - NULL
Apply kmeans to newiris, and store the clustering result in kc. The cluster number is set to 3.
(kc - kmeans(newiris, 3))
K-means clustering with 3 clusters of sizes 38, 50, 62
Cluster means:
Sepal.Length Sepal.Width Petal.Length Petal.Width
6.850000 3.073684 5.742105 2.071053
5.006000 3.428000 1.462000 0.246000
5.901613 2.748387 4.393548 1.433871
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 [30] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 1 3 3 3 3 3 [59] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3
[88] 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 1 1 1 1 3 1 1 1 1 1 1 3 3 1 [117] 1 1 1 3 1 3 1 3 1 1 3 3 1 1 1 1 1 3 1 1 1 1 3 1 1 1 3 1 1
[146] 1 3 1 1 3
Within cluster sum of squares by cluster:
[1] 23.87947 15.15100 39.82097
Available components:
[1] cluster centers withinss size
Compare the Species label with the clustering result
table(iris$Species, kc$cluster)
1 2 3
setosa 0 50 0 versicolor 2 0 48 virginica 36 0 14
Plot the clusters and their centres. Note that there are four dimensions in the data and that only the first two dimensions are used to draw the plot below. Some black points close to the green centre (asterisk) are actually closer to the black centre in the four dimensional space.
plot(newiris[c(Sepal.Length, Sepal.Width)], col=kc$cluster)
points(kc$centers[,c(Sepal.Length, Sepal.Width)], col=1:3, pch=8, cex=2)
on g.co0C6sc 0
on g.co0C6sc 0
£laGo
您可能关注的文档
最近下载
- (新版)社会体育指导员理论知识考试题库(含答案).docx VIP
- DB31T 1104-2018 城市轨道交通导向标识系统设计规范.docx VIP
- GB50461-2024:石油化工静设备安装工程施工质量验收规范.pptx VIP
- 2023年浙江省军队转业干部录用考试试题.docx VIP
- 口渴了-朋友帮你.ppt VIP
- Xikong西莱克低温机控制板SHXK814用户手册.pdf
- 爱迪生牛顿大发明攻略.doc VIP
- 重庆天齐锂电新材料有限公司新建1000吨_年高能锂电材料电池级金属锂项目环评报告.pdf VIP
- 朗文3A复习资料及垃圾分类作文8篇.doc VIP
- DB65T 3694-2015 现行哈萨克文与西里尔哈萨克文编码字符转换规则.docx VIP
原创力文档

文档评论(0)