In this session, we will discuss about the next unsupervised learning algorithm, which is key means
clustering.
Now, when I have explained the key and then Legatum to do you, I strictly said that this is one little
guarded them, which is often confused with the key means.
And so now we will have to go through again and means together so that we can actually draw a line between
both of these called.
So the very first thing which you need to know is what is key means so that we can draw a line between
key means and can and so that you don't get confused between them.
So what is key means it is just the names look similar, but the concept is a lot different.
So in case of K means clustering, he is the number of clusters which we will be creating.
So he means clustering, has a number of clusters, the mechanism that randomly initializes random centroid
in the feature space.
And at the time of initialization, the key points are not actual centroid of 30.
So the data point are then assigned to the nearest key point.
The same droids are then moved so that they are at the center of the current designated clusters, so
the very first difference between K means and again is that the key in means stands for the number of
clusters.
Why the key in key nearest neighbors stands for the number of neighbors which we are looking for.
Second and most important differences, that Cannon is in supervised learning algorithm, that is we
use it for making predictions via the key means algorithm is used for classifying or clustering the
data.
That is, it is an unsupervised learning one called.
Let us look for the.
So here we have the data, so let us say we have these points, so out of these points, if we want
to find two clusters, so what we will do is we will place two centroid points to it.
Now, we have placed these tools and right these tools androids would have been present at any place,
these are randomly placed in this particular.
Now, once they have placed these Synthroid, they then assign these data points, the points which
are nearest to this centroid, to this particular cluster, and the points which are nearest to the
second centroid to a cluster which belongs to this particular.
So now the boys have been assigned.
So the Redpoint belong to the cluster with the radix as Android, and the blue points belong to the
cluster with blue X as the centroid.
Now if you look at the data.
This doesn't really look like this in the auditioner.
So now the centroid will actually move towards the center of the cluster, which these androids have
created.
So now the points are moved to the center of the clusters.
So the Red Point is brought closer to the red cluster and the blue point is brought closer to the blue
cluster.
Now, once this has been done, now these points will again be rearranged so that the point assigned
to blue cluster.
Are having blue as the nearest point and the clairvoyants assigned to the red cluster are nearest to
the Red Point.
Now, again, once this has been done, the Red Point will be moved to the center of the data, which
we have, and no point will we move towards the center of the blue data.
And then again, the points will be reassigned based on their distance from the center right.
This will keep on repeating until the points do not move again, until the centroid stop moving.
So this is what he means.
Algorithm is here, the things to notice.
Number one, it will try to create circular clusters because it is looking for the area around the center.
Second thing is that no matter what kind of distribution is, it will still try to create a cluster.
Next point is that whenever the planes are assigned, whenever the same is pleased, so based on the
placement of these Synthroid, there would be different types of clusters which could be generated in
the end.
So it is not a sure, sure thing that we will get these two clusters.
The clusters might be based on the placement of the centroid at the initial point of time.
So after every initialization, we might get different clusters of different brands of the good.
Let us look at the assumptions which we have, the first assumption is that key means assumes the variance
of the distribution of each attribute to be spherical.
That is, it tries to create very good.
Cluster's, second thing is that already you have the same mediant, that is all we will be having the
same variants and here again, we will have to make sure that the data has been scaled properly.
Otherwise, the shape of cluster's, which we will receive, might not be as expected.
Next, the prior probability for all key clusters is the same that this each cluster has roughly equal
number of observations.
So whenever these clusters will be created, they will have roughly equal number of observations.
And apart from that.
Outliers will not be considered separate, outliers will also be included in these clusters, so a position
or a placement of an outlier can actually impact creation of these clusters.
So here you can see that this data is in uniform mixture and there is no actual cluster present in the
data, but just because we have pleased to say androids and the androids had to make clusters and thus
it has created two clusters in unknown cluster data.
Next here, you can see that the clusters are expected to be of the same size, that is, the clusters
will have similar number of data points in then.
So here, because this is a concentrated this has and this has more scattered.
That is why it looks like they have different sizes of data.
But actually they have seen size of the present in the clusters.
Next game means assigns to spherical fiesta.
So here we have a very good cluster.
So what will happen?
We would have expected that it will create cluster.
One cluster would be the outer ring and another cluster would be the inner area, inner circle area.
But actually it has created spherical clusters, cluster this half to one cluster and the other half
to the other cluster, which is not a good clustering technique.
So what are the rules for this particular algorithm?
Number one, it is simple.
Number two, it is flexible in nature.
Number three, it is suitable for a large dataset.
And lastly, it detects this very good Lesters very well.
It will be able to detect such clusters very nicely and these clusters, which are spherical in nature
very nicely.
So this one, again, it has detected very well.
But where we have some data, which is not really in very good form or here, you can see that these
are actually outliers.
And there are only two cluster sectors, one, this cluster and this cluster.
So they are actually only two clusters present.
So it was not able to determine that because we have already provided the number of clusters that we
need.
So no matter if there are extra clusters, present or not, it was to create one extra cluster instead
of creating just two clusters which are actually present in this data.
So what are the cons that is sensitive to the initial Synthroid location, so based on the central location
of this dog, the Thingo Spherical Cluster, then it is sensitive to outliers.
So that is here we have these outlier values present.
So it actually tried to include it in a cluster and hence ended up creating another cluster and adding
them into a cluster of.
Next is it always creates a spherical cluster, which we have seen here.
And lastly, it detects the.
It is not applicable for categorical data because a categorical data will not have so much difference
in the distances, so we cannot really use it for a categorical data.
Next, we will see a visualization of the K means clustering.
So this is one website where we can actually visualize the K means clustering.
So here.
We can select the initial centroid, so let us select the farthest point to be the initial centroid
here and the type of detail like the date of the O.
Up in my.
So here we expect the number of Kluster to be for where we have one to three and four clusters, so
let us start let us absent right to it.
On the centroid, one more centroid and another centroid, and let us start training this.
So it will.
Assign the points to these centroid.
Now we will update the same Droits, we will update the central location to the center of the data.
So it has updated the central location and based on the central location, now we will reassign the
points.
The boys have been reassigned to the nearest business, and right now we will again update this central
location.
Now, the central location has been updated.
Now we will reassign the points.
So if we keep on doing it, we'll just do this again and again until this point is actually the same,
that all of these data points.
So it has created four clusters, which was provided by us because we knew that there are four clusters,
but because it wanted to create a spherical cluster, it was not able to determine.
The location of the property, so let us have a look at it again, let us restart this.
So now let us place the center randomly and this time we will have the device can bring us the data.
So these are the different clusters.
These are the data points, letters and centroid as one, two, one, three.
Let us have four centroid.
Or just have to be sentenced for this and let us go.
So it has classified the points based on dissent right now.
Again, we will update the central location so it will bring the same rights to the center of the.
Now, again, we will reassign the points, so the points which have been misclassified like this,
red wine, these red points will be made for the college classes.
So it will reassign the points.
Now, the red points have been drawn into green and blue.
Now, again, we will update the central location.
Now, again, when we reassign the points, these points will be corrected.
So you can see it is always trying to create circular clusters and it will stop when we actually reach
the center of the data and all the points, all the clusters have almost equal number of data points.
So this is where it has stopped.
And you can see that there are almost equal number of data points present in all the three clusters.
So you can try different types of clusters here.
You can try different types of mixtures and then see what actually comes out of.
So let us try the Bembridge smiley.
Now, look at this, Bembridge Smiley, there are these outliers present, so it will it has actually
tried to assign these outliers also in the clusters.
So this is what we don't really want to have here.
And the creation of circular clusters has actually impacted the cluster formation.
So we want to have another variant or some other algorithm which might perform better than this.
So it will perform better.
Canines will perform better if we have spherically clusters so we can use it more, use more appropriately,
if we have spherically clusters and we have data points which are spherical in nature.