Iris <- read.csv("C:\\Users\\BALAJI\\Downloads\\Iris.csv")
Iris.features <- Iris
Iris.features$Id <- NULL
Iris.features$Species <- NULL
which(is.na(Iris.features))
## integer(0)
results <- kmeans(Iris.features,3)#3 different Iris species
results
## K-means clustering with 3 clusters of sizes 62, 38, 50
##
## Cluster means:
## SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm
## 1 5.901613 2.748387 4.393548 1.433871
## 2 6.850000 3.073684 5.742105 2.071053
## 3 5.006000 3.418000 1.464000 0.244000
##
## Clustering vector:
## [1] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
## [36] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
## [71] 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 2 2
## [106] 2 1 2 2 2 2 2 2 1 1 2 2 2 2 1 2 1 2 1 2 2 1 1 2 2 2 2 2 1 2 2 2 2 1 2
## [141] 2 2 1 2 2 2 1 2 2 1
##
## Within cluster sum of squares by cluster:
## [1] 39.82097 23.87947 15.24040
## (between_SS / total_SS = 88.4 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss"
## [5] "tot.withinss" "betweenss" "size" "iter"
## [9] "ifault"
table(Iris$Species,results$cluster)
##
## 1 2 3
## Iris-setosa 0 0 50
## Iris-versicolor 48 2 0
## Iris-virginica 14 36 0
plot(Iris[c("PetalLengthCm","PetalWidthCm")],col=results$cluster,pch=20)

plot(Iris[c("PetalLengthCm","PetalWidthCm")],col=Iris$Species,pch=20)

plot(Iris[c("SepalLengthCm","SepalWidthCm")],col=Iris$Species,pch=20)
plot(Iris[c("SepalLengthCm","SepalWidthCm")],col=Iris$Species,pch=20)
