Professional Documents
Culture Documents
➢ Example No 01):
> iris
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
| | | | | |
| | | | | |
| | | | | |
| | | | | |
148 6.5 3.0 5.2 2.0 virginica
149 6.2 3.4 5.4 2.3 virginica
150 5.9 3.0 5.1 1.8 virginica
> iriscopy=iris
> iriscopy
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
| | | | | |
| | | | | |
| | | | | |
| | | | | |
148 6.5 3.0 5.2 2.0 virginica
149 6.2 3.4 5.4 2.3 virginica
150 5.9 3.0 5.1 1.8 virginica
> iriscopy$Species<-NULL
> iriscopy
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 5.1 3.5 1.4 0.2
2 4.9 3.0 1.4 0.2
3 4.7 3.2 1.3 0.2
4 4.6 3.1 1.5 0.2
| | | | | |
| | | | | |
| | | | | |
| | | | | |
147 6.3 2.5 5.0 1.9
148 6.5 3.0 5.2 2.0
149 6.2 3.4 5.4 2.3
150 5.9 3.0 5.1 1.8
> Result<-kmeans(iriscopy,3)
> Result
K-means clustering with 3 clusters of sizes 38, 50, 62
Cluster means:
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 6.850000 3.073684 5.742105 2.071053
2 5.006000 3.428000 1.462000 0.246000
3 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 2 2 2
[33] 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 3 3 3 3 3 3
[65] 3 3 3 3 3 3 3 3 3 3 3 3 3 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
[97] 3 3 3 3 1 3 1 1 1 1 3 1 1 1 1 1 1 3 3 1 1 1 1 3 1 3 1 3 1 1 3 3
[129] 1 1 1 1 1 3 1 1 1 1 3 1 1 1 3 1 1 1 3 1 1 3
Within cluster sum of squares by cluster:
[1] 23.87947 15.15100 39.82097
(between_SS / total_SS = 88.4 %)
Available components:
1 2 3
setosa 0 50 0
versicolor 48 0 2
virginica 14 0 36
> plot(iris[c("Petal.Length","Petal.Width")],col=Result$cluster,main="Clu
stering Petal Length and Petal Width")
>
➢ Output:
>
Output:
➢ 02)Clustering of Petal length and Sepal Width.
> plot(iris$Petal.Length~iris$Sepal.Width,main="Clustering Petal lenght
and Sepal Width")
>
Output:
>
➢ Output:
>
➢ Output:
> plot(iris$Sepal.Length~iris$Sepal.Width)
> with(iris,text(iris$Sepal.Length~iris$Sepal.Width,labels=iris$Species,
pos=4,cex=0.6))
>
➢ Output:
➢ Output:
➢ Example No:02) Clustering and plotting cluster dendrogram on student
data.
➢ Excel Sheet:
Cluster means:
Roll.No Physics Chemistry Mathematics Biology
1 2.000000 80.00000 80.00000 82.00 79.00000
2 7.666667 66.66667 65.66667 73.00 78.33333
3 6.500000 64.50000 72.25000 64.25 65.50000
Information.Technology Obt..Marks Total.Marks Percentage
1 73.66667 394.6667 500 78.93333
2 72.33333 356.0000 500 71.20000
3 61.50000 328.0000 500 65.60000
Clustering vector:
[1] 1 1 1 3 2 3 3 2 3 2
Available components:
1 2 3
Aniket Lad 0 0 1
Nilesh Hatle 1 0 0
Parth Wagh 0 0 1
Pratibha Patil 0 0 1
Ravi Kasalkar 1 0 0
Rohan Desai 0 1 0
Sarika Jagtap 0 0 1
Siya Panchal 0 1 0
Snehal Jikamde 0 1 0
Sonal Parab 1 0 0
> plot(Student_Data[c("Physics","Chemistry")],col=Result$cluster)
>
➢ Output:
➢ 01)Clustering of Physics marks and Chemistry marks.
> plot(Student_Data$Physics~Student_Data$Chemistry,main="Clustering of
Physics marks and Chemistry marks.",xlab="Chemistry Marks",ylab="Physics
Marks")
>
➢ Output:
>
➢ Output:
➢ 03)Clustering of Physics marks and Information Technology marks.
> plot(Student_Data$Physics~Student_Data$Information.Technology,main="Clu
stering of Physics marks and Information Technology marks..",xlab="Inform
ation Technology Marks",ylab="Physics Marks")
>
➢ Output:
>
➢ Output:
> plot(Student_Data$Physics~Student_Data$Chemistry,main="Clustering of
Physics marks and Chemistry marks.")
> with(Student_Data,text(Student_Data$Physics~Student_Data$Chemistry,
labels=Student_Data$Student.Name,pos=4,cex=0.6))
>
➢ Output:
>
➢ Output: