Minor Project by Ali (Intrainz)
Minor Project by Ali (Intrainz)
DONE BY
head (i r i s . c e s s ;
ins.new??e)al.Lend-)i<- normalise(iris.frs'?Se:al.Ler:(;t)i)
iris.newS%epal.Width<- -ormalize(iris.rev Nepal.AiJth)
-r-s.newSFetal.Le.ng’.)i<- )oz-iiializu(uis.nc^.ñPctal.Lai.‹TLIi)
iris.newsPetal.Width<- nornoli e(iris.new$°e’al.Width)
head(iris.new,
#i [1] 61 39 50
resultFr=nrers # o:res value of cluster center ds! :’po:.’:' value{: centers for <-.’
result$cluster ^cives c7uster vector =.L. , 'g the o7uster wLere eaof record fa77s
9. Plot to see how Sepal.Length and Sepal .Width data po›nts have Deen d›stributed in clusters
1.0
0.8
O O
SepaI.Width
O O O OO O O
O O
0.4
O0 O OO O O O O O
. O O O OO O O
O .0
Sepal. Length
10. Plot to see how Sepal.Length and Sepal.Width data po›nts have been distributed originally as per ’ class” attr›bute ›n dataset
1.0
0.8
OO O
SepaI.Width
0.6
O 0 O O O OO O O
0 O O O O
O O0
0.4
Q O O O
OO O OO O O O O O
0.2
G O
Sepal.Length
O OO
1.0
OOOO O
OOOO O O
0.8
o o o
Petal.Width
0.6
O OOOOOO'O
OO O O O
0.4
0.2
0
O OOO O
O OOOOOO O
Petal.Length
12. Plot to see now Petal.Lengtn and Petal.Widfh data Ooints have been distributed originally as per “class” attribule in dataset
1.0
OOOO O
0.8
OO O OO O O O
Petal.Width
0.6
0 O OOO 0
O OOOOQO0
OO
0.4
O O O OO
0.2
library(qQploL2,
13. Install the package ggplot2 and import it and Plot the cluster results using ggplol
ggplot(irir.new, aes(Petal.fenj-h, Metal.Width, color = esult6cluster}) + gecm pair.K(,
0.75 — •• • •
result8cluster
• 1
0/>0- • •••••••
• 2
0.25 —
0.00 - • ••
O O
O O O O
SepaI.Width
0.6
D o Do o D O O0
O O O O O O O O O O O
0 0 0 0 0 0
oD
0.4
D O0 0 0 O O O 0 O O O0 O O 0 0
OO O0 0 0 O 0 O
0 0 0 0 0 0 0 0 O
D 0 0 O
O
0.2
0 0 0
0 O O
O O
Sepal.Length
ggplor (irir.rew, ate(Petal.Le.g-h, Petal.Win k, color = result c4ust )) * gecm_poir.t(:
1.00 — • ••
0.75 — •• • •
result8cluster
• 1
0/>0- • •••••••
• 2
0.25 —
0.00 - • ••
Sepal.Length ° ay, o
TO
0.0 O.2 0,4 0.8 0.8 1.0
Sepal.Width
k
0
’
O
Petal.Width
0
0,0 0.2 0.4 O.6 0.8 1.0
Petal.Length
## iris.cIas*
fi setosa versicolor virginica
#i 1 0 47 14
#1 2 0 3 36
fi 3 50 0
library(animation)
kJ <-kmezns.zni(iris.new, ?)
Total number of correctly classified instances are: 36 + 47 50= 133 Total number of incorrectly classified instances are: 3 + 14= 17
Accuracy = 133/(133+17) = 0.88 i.e our model has achieved 88% accuracy! In order to Improve this accuracy further, we may try different
values of k
0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0
0
.
0.0
0
Sep
SeLpa
L
a
0
06
6
Le
Le
+ng
n
h
+
g
h
o >
4
4
Find cluster? Move centers!
0
0
SepaI.Width SepaI.Width
0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0
0
.
0.0
0
Sep
SeLpa
L
a
0 O OØ O
06
6
Le
Le
+ng
n
h
+
g
h
D O O
4
4
Find cluster? Move centers!
0
0
SepaI.Width SepaI.Width
0.0 0.2 0.4 0.6 0.8 1.0 0.0 0.2 0.4 0.6 0.8 1.0
0
.
0.0
0
Sep
SeLpa
L
a
0
06
6
Le
Le
+ng
n
h
+
g
h
D O O
4
4
Find cluster? Move centers!
0
0
1.0
0.8
Move centers!
SepaI.Width
0.6
0.4
O
0.2
Sepal. Length
1.0
0.8
SepaI.Width
0.6
0.4
0.2
Sepal. Length
-0'
Jajsnjn
60t
Dim2
f9
joid ‹ajsnjg
k=2 k =3
cluster
cluster
M 1
1
2
2 0 2 2 0
Dim1 (739») Dim1 (73%)
k =4 k=5
cluster
cluster
1
1-
2
-2 0 2 -2 0 2
Dim1 (73%) Dim1 (73'f’e)
Conclusion
K means clustering algorithm with ihis dataset is executed and visualized using various r libraries like ggplot,animation,gridExtra,facfoextra.