Higher in this session, we will be implementing hierarchical clustering.
So let us begin the first thing which we will be doing is imposed a different library, such as import
fundus as Phoebe.
No, as and then we will import matplotlib.
Don't buy plot.
As a lot, next, we will import Seabourne.
So we lean forward from this.
We don't really need this one, let us import.
And Skillern.
Dr..
Pre processing.
Import.
Sked, this particular library will actually help us to scale the data.
Next from Escalon dot cluster, we will import the.
Argumentative flustering.
And the last we will implode this school, which is a metric for evaluation.
Let me run this.
Thought Matrix.
So after this, we will be importing the items dataset, which is the data set, which we will be using
for this particular tutorial.
So let me import defined by other.
Is equal to the filename that is itis.
NSV.
Next, I will give the data frames while the iris is equal to the dot read.
CSFI.
Inside this, I give the other.
So it should be treated like this only and I will give I just thought hard for you to see the detective.
So this is the data that we have.
So this data contains idee.
The sibilant separate the battlement battle delivered on the species of the.
Fly, which we have now, because we don't want to classify anything, we are just implementing the
clustering algorithm.
So clustering algorithm, we don't need the target values and we also don't need this idea because it
is a completely redundant column.
So I will drop these columns.
So I simply say iris dot drop.
And in this, I will give me a list of the columns which I want to drop, that this idea.
And the other one is species.
Next, I will give the axis, which is one, and in place equal to two.
Next, I will print the data set for you, so I'll say I just started.
And this is the data center, which we have now, now let us create clusters out of the first two columns.
So.
For this, we will, first of all, let us create the new grandmotherhood, so let us actually visualise
how hierarchical clustering would be working.
So we will import the library from sci fi.
So we will see from sci fi dot Plaistow.
Dorte.
Hirers.
He import.
Dendle.
Then, Joe.
Gramme.
And we want linkage from it, so we will import these libraries and now we will need to scale this particular
data to so how we will scale the Zetas.
So to scale this data, we have imported this particular package.
So we will simply see Iris.
Underscores the steady.
Is equal to feed dot data frame.
And the.
Give me.
Details, so we will skew the details of this skin and insight designed to give the dataset so Iris,
so this will simply scale the data.
Now, now I will have to give the columnists.
So the column will be columns equal to I can put this into a list for them and I get ideas dot columns
from.
So this will basically give me the list of the columns and I'm converting these columns into list from
next, let me display the data for you.
So I see Iris Dot sorry, underscore Steve.
Not this time, so that we can see what exactly is present in this data.
So this is the.
Data which has been circulating now.
Next, less let us create our program out of it, so to create an anagram, letters of creative, the
good for us.
So we will see if not not finger.
And inside this, we will give the big size, the big size is.
Let us say 10, Gummow five.
And we want to have a lot.
Got X neighbor.
So in the X level, I want to give.
Somphone.
Or simply say IDEX for simplicity.
And next, we will have.
Or just a simple index.
Next, we will have the available.
So in the vilely will let us have the distance.
Next, we will create.
The language.
So this will create the linkage for us, so we have given linkage and the data set and the method which
you want to create the linkage with and then from the data, we want to print the linkage which we have
created and provide the rotation and different details about the levels on the road.
So we will just print this.
It will take a little time.
And this is the dental of which has been created, so here you can see the.
No signs of the clusters, the values which are present, the indexes.
So here you can see that this is the second and next, so this is in the next.
You can see that these are the glass doors which have been created, so if we want to have two clusters,
we can simply break this distance equal to 15.
And these would be the two clusters which will be developing.
If you want three clusters, then we can break it at this point, and then we will have one, two and
three cluster.
That is green, red and blue.
So these are we have been highlighted, so these are the actual clusters which are present in this dataset,
which is actually being depicted here.
So now we will go ahead and plot a cluster.
So we report that we will again take a subset of data so that we can visualize it more properly.
So for that, let's take only these two columns.
So we will see.
Iris.
Is equal to Iris.
We have updated the data set, now we can see it is.
Describe.
So here you can see the values now begins and the scale, the data, or we could have simply done this
from the standardized details.
And it does do it with the standardized data.
So here you can see we have simply used these standardized data, which we had created earlier.
Now we will big of the clusters, so we will see clusters now also for creating the clusters we value
from several number of clusters, so.
Create this particular for loop, then we are outrating on top of clusters ranging from two to 19 and
we have created the cluster model object.
So this is the model object which has the object of argument, of clustering where we have provided
the number of clusters, the affinity, which is the distance, calculating metric which we have used
and the type of linkage which we have decided.
And we have provided the data, so we have the models which then predicted the model using the to standardize
data, which has only these two columns for now.
And we have gathered the label in Kluster label.
And after getting these values, we have actually calculated this old school.
Using the.
Standard data set and the label which has been generated.
And we are next printing the score for each number of clusters, so when we will run this, it will
give us all the number of clusters.
Now, we already know that the score, which is closest to one, is the best Szilard school.
And unfortunately, here the score is around zero point four.
So we will select this particular Senate school, which appears to be the maximum one.
Out of all the Senate scores, which we have, so we will select and is equal to three.
So let us actually implement this for these three cluster's.
So we will pick this up.
In this, we will put three, which is the best question which we have found.
So we can see these live average values for this.
Which comes out to be zero point forty, which is exactly the one which we have got.
So you can see that even out there running this particular method.
Again, it did not change the index value, it came up to be seen.
That is because the idea of clustering or we can see the hierarchical clustering is always giving the
same results, no matter how many times we are running it.
Because it is not dependent on any external criteria, it is dependent on the distances between the
points which are not changing.
Next, what we will be doing is so next we will create a blog.
So to create this particular plot, let us.
Get the neighbors for this, so for Lebas, these are the neighbors which we have.
And let us look at these levels to the data set, which we already have, so we will see Iris.
Under Iris and we will save Mehboob.
And unbelievable, we will for the values from the cluster labels.
Next, we will look at of.
So for that, we will see there's not a lot.
And inside this, we will give the details so we don't want to further aggression, so we will save
dreg.
Equal to.
Foy's.
Next, we will.
Provide the X and Y values so that X and Y values will be the values which we have here.
So these are the X and Y values, so X is equal to this and this is why want.
Next, we will.
Provide the data set, so data is.
Iris.
And for the.
Now, this, again, has to be in the eye of standard.
And this also has to be the standard data.
Next, which we will be doing is selecting the Hill, so we will give you as the cluster labels, which
we have.
Or we can simply give this one to.
So let's create this plot.
So this is the plot which have been generated, so here you can see that we have got three clear clusters
created.
So this is how we can use and limit on how people clustering for generating clusters for any type of
dataset.
Now we can use a different number of variables here.
We have used only two because it is easy to visualize for these two videos.
But we could have used all four of these and it would have created as good clusters as these ones.
But the only drawback here is we cannot apply this.
Or I must say that it does not prescribe to apply this for a large dataset, because then it would take
a lot of time to generate the data from all the clusters.
So this is about how the clustering next we will we will generate the gaming's clustering in comparison
to the hierarchical clustering once we have learned about the gaming's clusters.