r语言学习笔记-k平均算法.docxVIP

  • 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

文档评论(0)

1亿VIP精品文档

相关文档