#k-means clustering
library(cluster)
#Read the dataset iris
iris2 <- iris
#Remove Species column for cluster
iris2$Species <- NULL
#Apply k-means, vectors, components
(kmeans.result<- kmeans(iris2, 3))
#table species separation result
table(iris$Species, kmeans.result$cluster)
#Apply the k-means clustering
plot(iris2[c("Sepal.Length", "Sepal.Width")], col = kmeans.result$cluster)
# plot cluster centers
points(kmeans.result$centers[,c("Sepal.Length","Sepal.Width")],col=1:3,pch=8,cex=2)
library(cluster)
#Read the dataset iris
iris2 <- iris
#Remove Species column for cluster
iris2$Species <- NULL
#Apply k-means, vectors, components
(kmeans.result<- kmeans(iris2, 3))
#table species separation result
table(iris$Species, kmeans.result$cluster)
#Apply the k-means clustering
plot(iris2[c("Sepal.Length", "Sepal.Width")], col = kmeans.result$cluster)
# plot cluster centers
points(kmeans.result$centers[,c("Sepal.Length","Sepal.Width")],col=1:3,pch=8,cex=2)
No comments:
Post a Comment