Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

A4 Task

Name: Piyush Vishwakarma


Reg No: 18BCE10186

Q1. Using K-means clustering, cluster the following data into two clusters and
show each step.
{3, 5, 10, 13, 4, 21, 31, 12, 26}.
Give your step by step clear analysis?

Ans.
Given - {3, 5, 10, 13, 4, 21, 31, 12, 26}
First of all we will assign alternate values in a way that we get two clusters like
k1 = {3, 10, 4, 31, 26} and k2 = {5, 13, 21, 12}

Now we calculate mean for both k1 and k2.


c1 = Mean of k1 = 14.8
c2 = Mean of k2 = 12.75

Now comes the step where we assign the values to that cluster distance
computed from c1 and c2 is minimum.

Like for example


Let’s take the value “3” of k1 :
| 3-c1 | = 11.8
| 3-c2 | = 9.75
So the minimum is 9.75 so “3” goes to k2

So, k1 becomes = {}
And k2 becomes = {3}

Let’s take the value “10” of k1 :


| 10-c1 | = 4.8
| 10-c2 | = 2.75
So the minimum is 2.75 so “10” goes to k2

So, k1 becomes = {}
And k2 becomes = {3, 10}

Let’s take the value “4” of k1 :


| 4-c1 | = 10.8
| 4-c2 | = 8.75
So the minimum is 8.75 so “4” goes to k2

So, k1 becomes = {}
And k2 becomes = {3, 10, 4}

Let’s take the value “31” of k1 :


| 31-c1 | = 16.2
| 31-c2 | = 18.25
So the minimum is 13.2 so “31” goes to k1

So, k1 becomes = {31}


And k2 becomes = {3, 10, 4}

Let’s take the value “26” of k1 :


| 26-c1 | = 11.2
| 26-c2 | = 13.25
So the minimum is 11.2 so “26” goes to k1

So, k1 becomes = {31, 26}


And k2 becomes = {3, 10, 4}
Let’s take the value “5” of k2 :
| 5-c1 | = 9.8
| 5-c2 | = 7.75
So the minimum is 7.75 so “5” goes to k2

So, k1 becomes = {31, 26}


And k2 becomes = {3, 10, 4, 5}

Let’s take the value “13” of k2 :


| 13-c1 | = 1.8
| 13-c2 | = 0.25
So the minimum is 0.25 so “13” goes to k2

So, k1 becomes = {31, 26}


And k2 becomes = {3, 10, 4, 5, 13}

Let’s take the value “21” of k2 :


| 21-c1 | = 6.2
| 21-c2 | = 8.25
So the minimum is 6.2 so “21” goes to k1

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3, 10, 4, 5, 13}

Let’s take the value “12” of k2 :


| 12-c1 | = 2.8
| 12-c2 | = 0.75
So the minimum is 0.75 so “12” goes to k2

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3, 10, 4, 5, 13, 12}

Now again we will find mean


So c1 = (31 + 26 + 21)/3 = 26
And c2 = (3 + 10 + 4 + 5 + 13 + 12)/6 = 7.833

So again we will calculate minimum distance and find modified k1 and k2 :

Let’s take the value “31” of k1 :


| 31-c1 | = 16.2
| 31-c2 | = 18.25
So the minimum is 16.2 so “31” goes to k1

So, k1 becomes = {31}


And k2 becomes = {}

Let’s take the value “26” of k1 :


| 26-c1 | = 11.2
| 26-c2 | = 13.25
So the minimum is 11.2 so “26” goes to k1

So, k1 becomes = {31, 26}


And k2 becomes = {}

Let’s take the value “21” of k1 :


| 21-c1 | = 6.2
| 21-c2 | = 8.25
So the minimum is 6.2 so “21” goes to k1

So, k1 becomes = {31, 26, 21}


And k2 becomes = {}

Let’s take the value “3” of k2 :


| 3-c1 | = 11.8
| 3-c2 | = 9.75
So the minimum is 9.75 so “3” goes to k2

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3}

Let’s take the value “10” of k2 :


| 10-c1 | = 4.8
| 10-c2 | = 2.75
So the minimum is 2.75 so “3” goes to k2

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3, 10}

Let’s take the value “4” of k2 :


| 4-c1 | = 10.8
| 4-c2 | = 8.75
So the minimum is 8.75 so “4” goes to k2

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3, 10, 4}

Let’s take the value “5” of k2 :


| 5-c1 | = 9.8
| 5-c2 | = 7.75
So the minimum is 7.75 so “5” goes to k2

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3, 10, 4, 5}

Let’s take the value “13” of k2 :


| 13-c1 | = 1.8
| 13-c2 | = 0.25
So the minimum is 0.25 so “13” goes to k2

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3, 10, 4, 5, 13}
Let’s take the value “12” of k2 :
| 12-c1 | = 2.8
| 12-c2 | = 0.75
So the minimum is 0.75 so “12” goes to k2

So, k1 becomes = {31, 26, 21}


And k2 becomes = {3, 10, 4, 5, 13, 12}

We got the same k1 and k2 so this means now we can stop!!!

Therefore the final answer


k1 = {31, 26, 21} and k2 = {3, 10, 4, 5, 13, 12}.

Q2.
Formulate any four cluster scenarios to Calculate purity to measure the quality
of each cluster.

Ans.
The above image has 4 clusters (A, B, C, D) with three kinds of data items
coloured in aqua, green and yellow. So now we will find purity for all the
clusters.

Purity is the ratio between the dominant class in the cluster and the size of the
cluster.
W(i) = (1/n(i)) * max[n(ij)]

For A :
W(i) = (1/12)* max(2,4,6) = (1/12)*6 = 50%

For B :
W(i) = (1/12)* max(5,2,5) = (1/12)*5 = 41.6%

For C :
W(i) = (1/12)* max(3,6,3) = (1/12)*6 = 50%

For D :
W(i) = (1/12)* max(3,5,4) = (1/12)*5 = 41.6%

We come to the conclusion from computing the purity of the above four clusters
that cluster A and cluster C have 50% purity so they both have best quality in
this scenario.

You might also like